From C + + to. NET: Mapping native C + + to a common type system

Source: Internet
Author: User

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 &AMP;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;
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.