Personal page of Konjengbam

“Bluetooth adopter, technology enabler and innovative thinking”

Text Box: CString Alternative

Remarks

Since the interface is practically the same as MFC's CString, the same block of code that uses this version of string is workable under most cases when compiled or linked with MFC's CString class also. All that requires is to switch between the two versions by including appropriate header file.

Note that at the moment, no exception handling is carried out here in this class. Functions like Mid() throw CMemoryException in the real case. Mimicking that would require similar Exception class to be re-written or at least, some skeleton classes and similar heirarchies prepared. This work is left for future development.

The "dllexport" macro allows the class to be treated like a DLL library and all that a client needs is to include this header file and link with the libraries - StringObject.lib, StringObject.dll

Warning: The use of operators >> and << are restricted for stream operations only here. In MFC version, they represent object persistency support via CArchive.

View Interface file here

Purpose

This class has been developed to replace CString in the case of applications that require no MFC but still prefers to use MFC's CString style of handling strings.

 

No extra documentation is required so long as user follows CString of MFC, except at one or two cases, like - the function toString() has been provided to convert the object's type to ANSI version of string.

 

It may be noted that the interface methods are essentially same as that of the MFC's standard CString class. However, not all methods have been duplicated here because some of MFC' CString are platform specific. Also, format functionality has been deprecated here as this do not represent the actual abstraction of the current string class. However, based on platform for deployment of applications, one could use either wsprintf(), or sprintf() depending on either windows or console based in the respective target client applications.

 

In this class, which is ( I prefer to call StdString::CString ) more of standard in representation, the string data type is based upon STL's string library. This CString class acts as a wrapper around this standard string and provides similar ingredients and features of MFC's CString.

 

 

Implementation:

 

StdCString::CString

namespace StdCString {

class DllExport CString

{

public:

// Constructor(s) and Destructor CString(); // Default constructor

CString( const string& stdString ); // Constructs object from standard string

CString( const char* lpszString ); // Constructs from ANSI string, const char

CString( char* lpString ); // Constructs from ANSI string, char pointer

 

CString( const CString& rString ); // Copy constructor

~CString(); // Destructor, empties string

// Public operations

...

...

}

}

Hosted by www.Geocities.ws

1