///////////////////////////////////////////////////////////////////////// /// BridgeToCPPengine.cpp - Shows how to use traditional, unmanaged /// /// ver 1.0 C++ packaged as a dll library from /// /// managed code. /// /// /// /// Language: Visual C++, ver 7.0, Visual Studio.Net /// /// Platform: Dell Dimension 8100, Windows Pro 2000 /// /// Application: CSE681 Example /// /// Author: Jim Fawcett, CST 2-187, Syracuse Univ. /// /// (315) 443-3948, jfawcett@twcny.rr.com /// ///////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "bridgeToCPPengine.h" #include #include "Tok.h" #include using namespace bridgeToCPPengine; using namespace System; using namespace std; //----< delegate attaching toker to file to unmanaged class >---------- bool Bridge::attach(String* fileName) { return pTokMgr->SetStream(fileName); } //----< delegate GetTok to unmanaged class TokMgr >-------------------- bool Bridge::GetTok(String*& pTok) { return pTokMgr->GetTok(pTok); } // //----< create toker attached to named file >-------------------------- bool TokMgr::SetStream(String* fileName) { // convert .Net String to C++ string string temp; for(int i=0; iLength; ++i) { wchar_t wch = fileName->get_Chars(i); char ch = static_cast(wch); temp.append(1,ch); } // attempt to open file and create toker input.open(temp.c_str()); if(!input.good()) return false; _toker = new toker(input); return true; } //----< use tokenizer to extract token from stream >------------------- bool TokMgr::GetTok(String*& pTok) { // get token in std::string object std::string* temp = new std::string(""); bool ok = _toker->getTok(*temp); // convert C++ std::string to .Net String String* temper = new String(temp->c_str()); pTok = temper; temper = 0; delete temp; return ok; }