Directory
The unexpected place of the keyword
Inherited
Copy semantics
Lessons in the new language
Next Period content
In this column, the text query Language (TQL) query class hierarchy is converted from C + + to the. NET Common Type System (CTS). Here, I will use C++/CLI, but you can also use C #. The main advantage of C++/CLI is that it enables the application to be progressively transformed so that the source code level can mix native and managed C + + code. First, let's take a look at the implementation of the native Query base class, as shown in Figure 1.
Figure1 Native abstract Query base class
#include <vector>
#include <iostream>
#include <set>
#include <string>
#include <utility>
using namespace Std;
typedef pair< short, short > location;
Class Query {
Public
Virtual ~query () {delete _solution;}
query& operator= (const query&);
Virtual Set of operations ...
virtual void eval () = 0;
Virtual Query *clone () const = 0;
Virtual ostream& print (ostream &os) const = 0;
virtual bool Add_op (query*) {return true;}
virtual void display_solution (ostream &os = cout, int tabcnt = 0);
Actions that have been incorporated into the scope of the query
void Handle_tab (ostream &os, int tabcnt) const;
void Display_partial_solution ();
Const set< Short > *solution ();
Const vector< location > *locations () const {return &_loc;}
Supports the recognition of parentheses embedded in the query,
such as Alice && (Fiery | | magical)
void Lparen (short lp) {_lparen = LP;}
void Rparen (short rp) {_rparen = RP;}
Short Lparen () {return _lparen;}
Short Rparen () {return _rparen;}
void Print_lparen (short cnt, ostream& OS) const;
void Print_rparen (short cnt, ostream& OS) const;
Protected
Query (): _lparen (0), _rparen (0), _solution (0) {}
Query (const query &RHS)
: _loc (Rhs._loc), _solution (0),
_lparen (Rhs._lparen), _rparen (Rhs._rparen)
{}
Query (const vector<location> &loc)
: _loc (Loc), _solution (0),
_lparen (0), _rparen (0)
{}
set<short>* _vec2set (const vector<location>*);
Short _lparen;
Short _rparen;
Vector<location> _loc;
Set<short> *_solution;
};