[commit] r1220 - in trunk/GME: Common Gme
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Mar 30 12:55:19 CDT 2011
Author: ksmyth
Date: Wed Mar 30 12:55:19 2011
New Revision: 1220
Log:
Handle CStringW and CStringA separately
Modified:
trunk/GME/Common/CommonMfc.cpp
trunk/GME/Common/CommonMfc.h
trunk/GME/Common/CommonSmart.h
trunk/GME/Gme/GMEApp.cpp
trunk/GME/Gme/GMEOLEApp.cpp
Modified: trunk/GME/Common/CommonMfc.cpp
==============================================================================
--- trunk/GME/Common/CommonMfc.cpp Wed Mar 30 12:53:06 2011 (r1219)
+++ trunk/GME/Common/CommonMfc.cpp Wed Mar 30 12:55:19 2011 (r1220)
@@ -5,12 +5,12 @@
// --------------------------- Error
-void DisplayError(const char *msg, HRESULT hr)
+void DisplayError(const TCHAR *msg, HRESULT hr)
{
ASSERT( msg != NULL );
CString a;
- a.Format(" (0x%x)", hr);
+ a.Format(_T(" (0x%x)"), hr);
a.Insert(0, msg);
CString desc;
@@ -18,7 +18,7 @@
if( !desc.IsEmpty() )
{
- a += ": ";
+ a += _T(": ");
a += desc;
}
Modified: trunk/GME/Common/CommonMfc.h
==============================================================================
--- trunk/GME/Common/CommonMfc.h Wed Mar 30 12:53:06 2011 (r1219)
+++ trunk/GME/Common/CommonMfc.h Wed Mar 30 12:55:19 2011 (r1220)
@@ -10,33 +10,55 @@
// --------------------------- CString
-inline void CopyTo(const CString &s, BSTR *b) { CopyTo(s, s.GetLength(), b); }
-inline void CopyTo(const CString &s, VARIANT *v) { CopyTo(s, s.GetLength(), v); }
-inline void CopyTo(const CString &s, CComBstrObj &a) { CopyTo(s, s.GetLength(), a); }
-inline void CopyTo(const CString &s, CComVariant &a) { CopyTo(s, s.GetLength(), a); }
+inline void CopyTo(const CStringA &s, BSTR *b) { CopyTo(s, s.GetLength(), b); }
+inline void CopyTo(const CStringA &s, VARIANT *v) { CopyTo(s, s.GetLength(), v); }
+inline void CopyTo(const CStringA &s, CComBstrObj &a) { CopyTo(s, s.GetLength(), a); }
+inline void CopyTo(const CStringW &s, CComBstrObj &a) { a = CComBstrObj(s); }
+inline void CopyTo(const CStringA &s, CComVariant &a) { CopyTo(s, s.GetLength(), a); }
-inline void CopyTo(BSTR b, CString &s)
+inline void CopyTo(BSTR b, CStringA &s)
{
int len = GetCharLength(b);
CopyTo(b, s.GetBufferSetLength(len), len);
s.ReleaseBuffer(len);
}
-inline void CopyTo(VARIANT &v, CString &s)
+// Different name to avoid collision with wchar_t*
+inline void CopyBSTRTo(const BSTR b, CStringW& s)
+{
+ int len = SysStringLen(b);
+ memcpy(s.GetBufferSetLength(len), b, len);
+ s.ReleaseBuffer(len);
+}
+
+inline void CopyTo(const CComBstrObj& b, CStringW& s)
+{
+ CopyBSTRTo(b.p, s);
+}
+
+inline void CopyTo(const CComBSTR& b, CStringW& s)
+{
+ CopyBSTRTo(b.m_str, s);
+}
+
+inline void CopyTo(VARIANT &v, CStringA &s)
{
int len = GetCharLength(v);
CopyTo(v, s.GetBufferSetLength(len), len);
s.ReleaseBuffer(len);
}
-inline void CopyTo(const CString &s, CComBSTR &b) { CopyTo(s, &b); }
+inline void CopyTo(const CStringA &s, CComBSTR &b) { CopyTo(s, &b); }
+template<class char_t>
class PutOutCString
{
+ typedef ::ATL::CStringT< char_t, StrTraitMFC_DLL< char_t > > CString_t;
+
private:
- friend PutOutCString PutOut(CString &s);
+ friend PutOutCString PutOut(CString_t &s);
- PutOutCString(CString &a) : s(a)
+ PutOutCString(CString_t &a) : s(a)
{
ASSERT( &s != NULL );
}
@@ -56,12 +78,17 @@
private:
CComBstrObj b;
- CString &s;
+ CString_t &s;
};
-inline PutOutCString PutOut(CString &s)
+inline PutOutCString<char> PutOut(CStringA &s)
+{
+ return PutOutCString<char>(s);
+}
+
+inline PutOutCString<wchar_t> PutOut(CStringW &s)
{
- return PutOutCString(s);
+ return PutOutCString<wchar_t>(s);
}
class PutInCString
@@ -71,7 +98,7 @@
PutInCString(T t) { CopyTo(t, b); }
operator const CString &() { return b; }
- operator const char *() { return b; }
+ operator const TCHAR *() { return b; }
CString b;
};
Modified: trunk/GME/Common/CommonSmart.h
==============================================================================
--- trunk/GME/Common/CommonSmart.h Wed Mar 30 12:53:06 2011 (r1219)
+++ trunk/GME/Common/CommonSmart.h Wed Mar 30 12:55:19 2011 (r1220)
@@ -154,6 +154,12 @@
const CComBstrObj &operator=(const CComBstrObj &q) { if(p) SysFreeString(p);
p = SysAllocStringLen(q, q.Length()); return *this; }
+ CComBstrObj& operator=(CComBstrObj&& q) {
+ if (p) SysFreeString(p);
+ p = q.p;
+ q.p = NULL;
+ return *this;
+ }
operator BSTR() const { return p; }
unsigned int Length() const { return p ? SysStringLen(p) : 0; }
void Empty() { if( p ) { SysFreeString(p); p = NULL; } }
Modified: trunk/GME/Gme/GMEApp.cpp
==============================================================================
--- trunk/GME/Gme/GMEApp.cpp Wed Mar 30 12:53:06 2011 (r1219)
+++ trunk/GME/Gme/GMEApp.cpp Wed Mar 30 12:55:19 2011 (r1220)
@@ -2218,7 +2218,7 @@
COMTHROW( dumper.CoCreateInstance(L"Mga.MgaDumper") );
ASSERT( dumper != NULL );
- COMTHROW( dumper->DumpProject(theApp.mgaProject, PutInBstr(xmlname)) );
+ COMTHROW( dumper->DumpProject(theApp.mgaProject, PutInBstr(CString(xmlname))) );
SafeCloseProject();
@@ -2253,7 +2253,7 @@
COMTHROW( parser.CoCreateInstance(L"Mga.MgaParser") );
ASSERT( parser != NULL );
if(mgaConstMgr) COMTHROW(mgaConstMgr->Enable(false));
- COMTHROW(parser->ParseProject(mgaProject, PutInBstr(xmlname)) );
+ COMTHROW(parser->ParseProject(mgaProject, PutInBstr(CString(xmlname))) );
{
char buf[200];
sprintf(buf, "The model has been updated\nCurrent ID: %s\nThe original model has been saved to %s",
Modified: trunk/GME/Gme/GMEOLEApp.cpp
==============================================================================
--- trunk/GME/Gme/GMEOLEApp.cpp Wed Mar 30 12:53:06 2011 (r1219)
+++ trunk/GME/Gme/GMEOLEApp.cpp Wed Mar 30 12:55:19 2011 (r1220)
@@ -273,7 +273,7 @@
COMTHROW( dumper.CoCreateInstance(L"Mga.MgaDumper") );
ASSERT( dumper != NULL );
- COMTHROW( dumper->DumpProject(theApp.mgaProject,PutInBstr(connstr)) );
+ COMTHROW( dumper->DumpProject(theApp.mgaProject,PutInBstr(CString(connstr))) );
}
catch (hresult_exception &){
@@ -295,7 +295,7 @@
if(theApp.mgaConstMgr) COMTHROW(theApp.mgaConstMgr->Enable(false));
- COMTHROW(parser->ParseProject(theApp.mgaProject,PutInBstr(connstr)) );
+ COMTHROW(parser->ParseProject(theApp.mgaProject,PutInBstr(CString(connstr))) );
}
catch (hresult_exception &){
More information about the gme-commit
mailing list