summaryrefslogtreecommitdiff
path: root/orkbasecxx
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2005-10-20 13:40:58 +0000
committerHenri Herscher <henri@oreka.org>2005-10-20 13:40:58 +0000
commit7e1d63dd9fd149e4934bf77095c8610fac786b04 (patch)
tree5fe486a1b0300c3b84fb559107a868e5cc2c95da /orkbasecxx
parent467768fc956fc3e5a253373f26c71c681b31b6b8 (diff)
First checkin
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@2 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx')
-rw-r--r--orkbasecxx/AudioCapture.cpp201
-rw-r--r--orkbasecxx/AudioCapture.h109
-rw-r--r--orkbasecxx/BUILD.txt2
-rw-r--r--orkbasecxx/Makefile.am14
-rw-r--r--orkbasecxx/Makefile.cvs8
-rw-r--r--orkbasecxx/Object.cpp54
-rw-r--r--orkbasecxx/Object.h56
-rw-r--r--orkbasecxx/ObjectFactory.cpp44
-rw-r--r--orkbasecxx/ObjectFactory.h39
-rw-r--r--orkbasecxx/OrkBase.cpp27
-rw-r--r--orkbasecxx/OrkBase.dsp330
-rw-r--r--orkbasecxx/OrkBase.dsw29
-rw-r--r--orkbasecxx/OrkBase.h26
-rw-r--r--orkbasecxx/OrkClient.cpp132
-rw-r--r--orkbasecxx/OrkClient.h43
-rw-r--r--orkbasecxx/StdString.h3747
-rw-r--r--orkbasecxx/Utils.h93
-rw-r--r--orkbasecxx/config.guess1
-rw-r--r--orkbasecxx/config.sub1
-rw-r--r--orkbasecxx/configure.in10
-rw-r--r--orkbasecxx/install-sh276
-rw-r--r--orkbasecxx/ltmain.sh1
-rw-r--r--orkbasecxx/messages/AsyncMessage.cpp46
-rw-r--r--orkbasecxx/messages/AsyncMessage.h48
-rw-r--r--orkbasecxx/messages/Makefile.am8
-rw-r--r--orkbasecxx/messages/Message.cpp41
-rw-r--r--orkbasecxx/messages/Message.h55
-rw-r--r--orkbasecxx/messages/SyncMessage.cpp14
-rw-r--r--orkbasecxx/messages/SyncMessage.h31
-rw-r--r--orkbasecxx/missing336
-rw-r--r--orkbasecxx/mkinstalldirs111
-rw-r--r--orkbasecxx/serializers/DomSerializer.cpp157
-rw-r--r--orkbasecxx/serializers/DomSerializer.h81
-rw-r--r--orkbasecxx/serializers/Makefile.am10
-rw-r--r--orkbasecxx/serializers/Serializer.cpp312
-rw-r--r--orkbasecxx/serializers/Serializer.h86
-rw-r--r--orkbasecxx/serializers/SingleLineSerializer.cpp203
-rw-r--r--orkbasecxx/serializers/SingleLineSerializer.h44
-rw-r--r--orkbasecxx/serializers/UrlSerializer.cpp161
-rw-r--r--orkbasecxx/serializers/UrlSerializer.h44
-rw-r--r--orkbasecxx/serializers/XmlRpcSerializer.cpp47
-rw-r--r--orkbasecxx/serializers/XmlRpcSerializer.h45
42 files changed, 7123 insertions, 0 deletions
diff --git a/orkbasecxx/AudioCapture.cpp b/orkbasecxx/AudioCapture.cpp
new file mode 100644
index 0000000..3178f2e
--- /dev/null
+++ b/orkbasecxx/AudioCapture.cpp
@@ -0,0 +1,201 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#include "Utils.h"
+#include "math.h"
+#include "AudioCapture.h"
+
+
+AudioChunk::AudioChunk()
+{
+ m_encoding = UnknownAudio;
+ m_timestamp = 0;
+ m_sequenceNumber = 0;
+ m_numBytes = 0;
+ m_pBuffer = NULL;
+ m_sampleRate = 8000;
+}
+
+AudioChunk::~AudioChunk()
+{
+ if(m_pBuffer)
+ {
+ free(m_pBuffer);
+ }
+}
+
+void AudioChunk::SetBuffer(void* pBuffer, size_t numBytes, AudioEncodingEnum encoding, unsigned int timestamp, unsigned int sequenceNumber)
+{
+ if(m_pBuffer)
+ {
+ free(m_pBuffer);
+ m_numBytes = 0;
+ }
+ if(numBytes && pBuffer)
+ {
+ m_pBuffer = malloc(numBytes);
+ if (!m_pBuffer)
+ {
+ CStdString numBytesString = IntToString(numBytes);
+ throw("AudioChunk::AudioChunk: could not malloc a buffer of size:" + numBytesString);
+ }
+ else
+ {
+ m_numBytes = numBytes;
+ memcpy(m_pBuffer, pBuffer, numBytes);
+ m_encoding = encoding;
+ m_timestamp = timestamp;
+ m_sequenceNumber = sequenceNumber;
+ }
+ }
+}
+
+int AudioChunk::GetNumSamples()
+{
+ switch(m_encoding)
+ {
+ case PcmAudio:
+ return m_numBytes/2;
+ case AlawAudio: case UlawAudio:
+ return m_numBytes;
+ default:
+ throw(CStdString("AudioChunk::GetNumSamples: unknown encoding"));
+ }
+}
+
+double AudioChunk::GetDurationSec()
+{
+ int i = 0;
+ return ((double)GetNumSamples())/((double)m_sampleRate);
+}
+
+
+double AudioChunk::ComputeRms()
+{
+ double rmsValue = 0;
+ if(m_encoding == PcmAudio)
+ {
+ for(int i=0; i<GetNumSamples(); i++)
+ {
+ rmsValue += ((short *)m_pBuffer)[i] * ((short *)m_pBuffer)[i];
+ }
+ rmsValue = sqrt(rmsValue/GetNumSamples());
+ }
+ return rmsValue;
+}
+
+double AudioChunk::ComputeRmsDb()
+{
+ double rmsDbValue = 10 * log10(1.0/32768.0); // default value, the lowest possible
+ if(m_encoding == PcmAudio)
+ {
+ rmsDbValue = 10 * log10(ComputeRms()/32768.0);
+ }
+ return rmsDbValue;
+}
+
+
+
+//=================================
+
+CaptureEvent::CaptureEvent()
+{
+ m_timestamp = 0;
+ m_type = EtUnknown;
+}
+
+CStdString CaptureEvent::DirectionToString(int direction)
+{
+ switch(direction)
+ {
+ case DirIn:
+ return DIR_IN;
+ case DirOut:
+ return DIR_OUT;
+ }
+ return DIR_UNKN;
+}
+
+int CaptureEvent::DirectionToEnum(CStdString& dir)
+{
+ if(dir.CompareNoCase(DIR_IN) == 0)
+ {
+ return DirIn;
+ }
+ else if(dir.CompareNoCase(DIR_OUT) == 0)
+ {
+ return DirOut;
+ }
+ return DirUnkn;
+}
+
+CStdString CaptureEvent::EventTypeToString(int eventTypeEnum)
+{
+ switch(eventTypeEnum)
+ {
+ case EtUnknown:
+ return ET_UNKNOWN;
+ case EtStart:
+ return ET_START;
+ case EtStop:
+ return ET_STOP;
+ case EtDirection:
+ return ET_DIRECTION;
+ case EtRemoteParty:
+ return ET_REMOTEPARTY;
+ case EtLocalParty:
+ return ET_LOCALPARTY;
+ case EtLocalEntryPoint:
+ return ET_LOCALENTRYPOINT;
+ case EtKeyValue:
+ return ET_KEYVALUE;
+ }
+ return ET_INVALID;
+}
+
+int CaptureEvent::EventTypeToEnum(CStdString& eventTypeString)
+{
+ int eventTypeEnum = EtUnknown;
+ if(eventTypeString.CompareNoCase(ET_START) == 0)
+ {
+ eventTypeEnum = EtStart;
+ }
+ else if (eventTypeString.CompareNoCase(ET_STOP) == 0)
+ {
+ eventTypeEnum = EtStop;
+ }
+ else if (eventTypeString.CompareNoCase(ET_DIRECTION) == 0)
+ {
+ eventTypeEnum = EtDirection;
+ }
+ else if (eventTypeString.CompareNoCase(ET_REMOTEPARTY) == 0)
+ {
+ eventTypeEnum = EtRemoteParty;
+ }
+ else if (eventTypeString.CompareNoCase(ET_LOCALPARTY) == 0)
+ {
+ eventTypeEnum = EtLocalParty;
+ }
+ else if (eventTypeString.CompareNoCase(ET_LOCALENTRYPOINT) == 0)
+ {
+ eventTypeEnum = EtLocalEntryPoint;
+ }
+ else if (eventTypeString.CompareNoCase(ET_KEYVALUE) == 0)
+ {
+ eventTypeEnum = EtKeyValue;
+ }
+ return eventTypeEnum;
+}
+
diff --git a/orkbasecxx/AudioCapture.h b/orkbasecxx/AudioCapture.h
new file mode 100644
index 0000000..cb5a234
--- /dev/null
+++ b/orkbasecxx/AudioCapture.h
@@ -0,0 +1,109 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __AUDIOCAPTURE_H__
+#define __AUDIOCAPTURE_H__
+
+#include "time.h"
+#include "StdString.h"
+#include "OrkBase.h"
+
+#include "boost/shared_ptr.hpp"
+
+/** This class represents a piece of audio.
+*/
+class DLL_IMPORT_EXPORT AudioChunk
+{
+public:
+ typedef enum
+ {
+ UnknownAudio = 0,
+ PcmAudio = 1,
+ AlawAudio = 2,
+ UlawAudio = 3,
+ InvalidAudio = 4
+ } AudioEncodingEnum;
+
+ AudioChunk();
+ ~AudioChunk();
+
+ /** Copy external buffer to internal buffer. Create internal buffer if necessary */
+ void SetBuffer(void* pBuffer, size_t numBytes, AudioEncodingEnum, unsigned int timestamp = 0, unsigned int sequenceNumber = 0);
+
+ /** Computes the Root-Mean-Square power value of the buffer */
+ double ComputeRms();
+ /** Compute the RMS decibel value of the buffer with a 0 dB reference being the maximum theoretical RMS power of the buffer (2^15) */
+ double ComputeRmsDb();
+
+ int GetNumSamples();
+ double GetDurationSec();
+
+ AudioEncodingEnum m_encoding;
+ unsigned int m_numBytes;
+ void * m_pBuffer;
+ unsigned int m_timestamp; // usually: relative timestamp measured in samples
+ unsigned int m_sequenceNumber;
+ unsigned int m_sampleRate;
+};
+
+typedef boost::shared_ptr<AudioChunk> AudioChunkRef;
+
+class DLL_IMPORT_EXPORT CaptureEvent
+{
+public:
+ CaptureEvent();
+
+#define DIR_IN "in"
+#define DIR_OUT "out"
+#define DIR_UNKN "unkn"
+ typedef enum {
+ DirIn = 0,
+ DirOut = 1,
+ DirUnkn = 2
+ } DirectionEnum;
+ static CStdString DirectionToString(int);
+ static int DirectionToEnum(CStdString& dir);
+
+#define ET_UNKNOWN "unknown"
+#define ET_START "start"
+#define ET_STOP "stop"
+#define ET_DIRECTION "direction"
+#define ET_REMOTEPARTY "remoteparty"
+#define ET_LOCALPARTY "localparty"
+#define ET_LOCALENTRYPOINT "localentrypoint"
+#define ET_KEYVALUE "keyvalue"
+#define ET_INVALID "invalid"
+ typedef enum
+ {
+ EtUnknown = 0,
+ EtStart = 1,
+ EtStop = 2,
+ EtDirection = 3,
+ EtRemoteParty = 4,
+ EtLocalParty = 5,
+ EtLocalEntryPoint = 6,
+ EtKeyValue = 7,
+ EtInvalid = 8
+ } EventTypeEnum;
+ static CStdString EventTypeToString(int eventTypeEnum);
+ static int EventTypeToEnum(CStdString&);
+
+ time_t m_timestamp;
+ EventTypeEnum m_type;
+ CStdString m_key;
+ CStdString m_value;
+};
+
+typedef boost::shared_ptr<CaptureEvent> CaptureEventRef;
+#endif
+
diff --git a/orkbasecxx/BUILD.txt b/orkbasecxx/BUILD.txt
new file mode 100644
index 0000000..70f9ba3
--- /dev/null
+++ b/orkbasecxx/BUILD.txt
@@ -0,0 +1,2 @@
+
+To build this, please see ../BUILD_C++.txt \ No newline at end of file
diff --git a/orkbasecxx/Makefile.am b/orkbasecxx/Makefile.am
new file mode 100644
index 0000000..b660bf6
--- /dev/null
+++ b/orkbasecxx/Makefile.am
@@ -0,0 +1,14 @@
+# not a GNU package. You can remove this line, if
+# have all needed files, that a GNU package needs
+AUTOMAKE_OPTIONS = foreign 1.4
+
+
+lib_LTLIBRARIES = liborkbase.la
+liborkbase_la_LDFLAGS =
+liborkbase_la_SOURCES = OrkBase.cpp Object.cpp ObjectFactory.cpp \
+ OrkClient.cpp AudioCapture.cpp
+#INCLUDES = -I/projects/ext/xmlrpc++/xmlrpc++0.7/src
+SUBDIRS = messages serializers
+liborkbase_la_LIBADD = $(top_builddir)/serializers/libserializers.la \
+ $(top_builddir)/messages/libmessages.la
+AM_CXXFLAGS = -D_REENTRANT
diff --git a/orkbasecxx/Makefile.cvs b/orkbasecxx/Makefile.cvs
new file mode 100644
index 0000000..d160702
--- /dev/null
+++ b/orkbasecxx/Makefile.cvs
@@ -0,0 +1,8 @@
+default: all
+
+all:
+ aclocal
+ autoheader
+ automake
+ autoconf
+
diff --git a/orkbasecxx/Object.cpp b/orkbasecxx/Object.cpp
new file mode 100644
index 0000000..66ceeb9
--- /dev/null
+++ b/orkbasecxx/Object.cpp
@@ -0,0 +1,54 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "serializers/SingleLineSerializer.h"
+#include "serializers/DomSerializer.h"
+#include "serializers/UrlSerializer.h"
+#include "Object.h"
+
+
+CStdString Object::SerializeSingleLine()
+{
+ SingleLineSerializer serializer(this);
+ return serializer.Serialize();
+}
+
+void Object::DeSerializeSingleLine(CStdString& input)
+{
+ SingleLineSerializer serializer(this);
+ serializer.DeSerialize(input);
+}
+
+void Object::SerializeDom(XERCES_CPP_NAMESPACE::DOMDocument* doc)
+{
+ DomSerializer serializer(this);
+ serializer.Serialize(doc);
+}
+
+void Object::DeSerializeDom(DOMNode* doc)
+{
+ DomSerializer serializer(this);
+ serializer.DeSerialize(doc);
+}
+
+CStdString Object::SerializeUrl()
+{
+ UrlSerializer serializer(this);
+ return serializer.Serialize();
+}
+
+void Object::DeSerializeUrl(CStdString& input)
+{
+ UrlSerializer serializer(this);
+ serializer.DeSerialize(input);
+}
diff --git a/orkbasecxx/Object.h b/orkbasecxx/Object.h
new file mode 100644
index 0000000..ba8128e
--- /dev/null
+++ b/orkbasecxx/Object.h
@@ -0,0 +1,56 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __OBJECT_H__
+#define __OBJECT_H__
+
+#include "OrkBase.h"
+#include "boost/shared_ptr.hpp"
+#include "xercesc/dom/DOMNode.hpp"
+
+class Serializer;
+class Object;
+
+using namespace XERCES_CPP_NAMESPACE;
+
+typedef boost::shared_ptr<Object> ObjectRef;
+
+#define OBJECT_TYPE_TAG "type"
+
+/** An Object is the equivalent of a Java Object
+*/
+class DLL_IMPORT_EXPORT Object
+{
+public:
+ virtual void Define(Serializer* s) = 0;
+ virtual void Validate() = 0;
+
+ CStdString SerializeSingleLine();
+ void DeSerializeSingleLine(CStdString& input);
+
+ void SerializeDom(XERCES_CPP_NAMESPACE::DOMDocument* doc);
+ void DeSerializeDom(DOMNode* doc);
+
+ CStdString SerializeUrl();
+ void DeSerializeUrl(CStdString& input);
+
+ virtual CStdString GetClassName() = 0;
+ virtual ObjectRef NewInstance() = 0;
+
+ virtual ObjectRef Process() = 0;
+};
+
+
+
+#endif
+
diff --git a/orkbasecxx/ObjectFactory.cpp b/orkbasecxx/ObjectFactory.cpp
new file mode 100644
index 0000000..173d581
--- /dev/null
+++ b/orkbasecxx/ObjectFactory.cpp
@@ -0,0 +1,44 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#include "ObjectFactory.h"
+
+
+void ObjectFactory::Initialize()
+{
+ ;
+}
+
+ObjectRef ObjectFactory::NewInstance(CStdString& className)
+{
+ std::map<CStdString, ObjectRef>::iterator pair;
+ pair = m_classes.find(className);
+
+ if (pair == m_classes.end())
+ {
+ return ObjectRef(); // Empty
+ }
+ else
+ {
+ return pair->second;
+ }
+}
+
+void ObjectFactory::RegisterObject(ObjectRef& objRef)
+{
+ m_classes.insert(std::make_pair(objRef->GetClassName(), objRef));
+}
+
+
diff --git a/orkbasecxx/ObjectFactory.h b/orkbasecxx/ObjectFactory.h
new file mode 100644
index 0000000..52f61b7
--- /dev/null
+++ b/orkbasecxx/ObjectFactory.h
@@ -0,0 +1,39 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __OBJECTFACTORY_H__
+#define __OBJECTFACTORY_H__
+
+#include "ace/Singleton.h"
+#include <map>
+#include "StdString.h"
+#include "Object.h"
+
+/** The ObjectFactory can be used to instanciate Objects based on class name.
+ All existing Objects must be registered to the ObjectFactory at startup.
+*/
+class DLL_IMPORT_EXPORT ObjectFactory
+{
+public:
+ void Initialize();
+ ObjectRef NewInstance(CStdString& className);
+
+ void RegisterObject(ObjectRef&);
+private:
+ std::map<CStdString, ObjectRef> m_classes;
+};
+
+typedef ACE_Singleton<ObjectFactory, ACE_Thread_Mutex> ObjectFactorySingleton;
+
+#endif
+
diff --git a/orkbasecxx/OrkBase.cpp b/orkbasecxx/OrkBase.cpp
new file mode 100644
index 0000000..98d7d1b
--- /dev/null
+++ b/orkbasecxx/OrkBase.cpp
@@ -0,0 +1,27 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+// Defines the entry point for the DLL application.
+//
+
+//#include "stdafx.h"
+/*
+BOOL APIENTRY DllMain( HANDLE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved
+ )
+{
+ return TRUE;
+}
+*/
+
diff --git a/orkbasecxx/OrkBase.dsp b/orkbasecxx/OrkBase.dsp
new file mode 100644
index 0000000..36c004f
--- /dev/null
+++ b/orkbasecxx/OrkBase.dsp
@@ -0,0 +1,330 @@
+# Microsoft Developer Studio Project File - Name="OrkBase" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=OrkBase - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "OrkBase.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "OrkBase.mak" CFG="OrkBase - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "OrkBase - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "OrkBase - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "BUILD_ORKBASE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FD /c
+# SUBTRACT CPP /YX /Yc /Yu
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 xerces-c_2.lib log4cxx.lib ace.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Release" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib"
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Cmds=copy Release\OrkBase.dll ..\OrkAudio\OrkBase.dll
+# End Special Build Tool
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /I "C:\devExt\boost\boost_1_32_0" /I "C:\devExt\ACE_wrappers" /I "C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\include" /I "C:\devExt\log4cxx\log4cxx-0.9.7\include" /D "BUILD_ORKBASE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /FD /GZ /c
+# SUBTRACT CPP /YX /Yc /Yu
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 xerces-c_2D.lib log4cxx.lib aced.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /map /debug /machine:I386 /out:"Debug/OrkBaseD.dll" /pdbtype:sept /libpath:"C:\devExt\ACE_wrappers\lib" /libpath:"C:\devExt\log4cxx\log4cxx-0.9.7\msvc\Lib\Debug" /libpath:"C:\devExt\xerces++\xerces-c_2_6_0-windows_nt-msvc_60\lib"
+# Begin Special Build Tool
+SOURCE="$(InputPath)"
+PostBuild_Cmds=copy Debug\OrkBaseD.dll ..\OrkAudio\OrkBaseD.dll
+# End Special Build Tool
+
+!ENDIF
+
+# Begin Target
+
+# Name "OrkBase - Win32 Release"
+# Name "OrkBase - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Group "Serializers"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\Serializers\DomSerializer.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\DomSerializer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\Serializer.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\Serializer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\SingleLineSerializer.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\SingleLineSerializer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\UrlSerializer.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\UrlSerializer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\XmlRpcSerializer.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Serializers\XmlRpcSerializer.h
+# End Source File
+# End Group
+# Begin Group "Messages"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\Messages\AsyncMessage.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Messages\AsyncMessage.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Messages\Message.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Messages\Message.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Messages\SyncMessage.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Messages\SyncMessage.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\AudioCapture.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\AudioCapture.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Object.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\Object.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\ObjectFactory.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\ObjectFactory.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\OrkBase.cpp
+
+!IF "$(CFG)" == "OrkBase - Win32 Release"
+
+!ELSEIF "$(CFG)" == "OrkBase - Win32 Debug"
+
+# SUBTRACT CPP /YX /Yc /Yu
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\OrkBase.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\OrkClient.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\OrkClient.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\StdString.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Utils.h
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\StdAfx.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# End Target
+# End Project
diff --git a/orkbasecxx/OrkBase.dsw b/orkbasecxx/OrkBase.dsw
new file mode 100644
index 0000000..b9c8f99
--- /dev/null
+++ b/orkbasecxx/OrkBase.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "OrkBase"=.\OrkBase.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/orkbasecxx/OrkBase.h b/orkbasecxx/OrkBase.h
new file mode 100644
index 0000000..95f1ef6
--- /dev/null
+++ b/orkbasecxx/OrkBase.h
@@ -0,0 +1,26 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#ifdef WIN32
+ #ifdef BUILD_ORKBASE
+ #define DLL_IMPORT_EXPORT __declspec( dllexport )
+ #else
+ #define DLL_IMPORT_EXPORT __declspec( dllimport )
+ #endif
+#else
+ #define DLL_IMPORT_EXPORT
+#endif
+
+#include "StdString.h"
diff --git a/orkbasecxx/OrkClient.cpp b/orkbasecxx/OrkClient.cpp
new file mode 100644
index 0000000..900656d
--- /dev/null
+++ b/orkbasecxx/OrkClient.cpp
@@ -0,0 +1,132 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "Utils.h"
+#include "OrkClient.h"
+#include "ace/INET_Addr.h"
+#include "ace/SOCK_Connector.h"
+#include "ace/SOCK_Stream.h"
+
+#ifdef WIN32
+ #define IOV_TYPE char*
+#else
+ #define IOV_TYPE void*
+#endif
+
+bool OrkHttpClient::ExecuteUrl(CStdString& request, CStdString& response, CStdString& hostname, int tcpPort, int timeout)
+{
+ ACE_SOCK_Connector connector;
+ ACE_SOCK_Stream peer;
+ ACE_INET_Addr peer_addr;
+ ACE_Time_Value aceTimeout (timeout);
+
+ char szTcpPort[10];
+ sprintf(szTcpPort, "%d", tcpPort);
+ iovec iov[8];
+ iov[0].iov_base = (IOV_TYPE)"GET ";
+ iov[0].iov_len = 4; // Length of "GET ".
+ iov[1].iov_base = (PSTR)(PCSTR)request;
+ iov[1].iov_len = request.size();
+ iov[2].iov_base = (IOV_TYPE)" HTTP/1.0\r\n";
+ iov[2].iov_len = 11;
+ iov[3].iov_base = (IOV_TYPE)"Host: ";
+ iov[3].iov_len = 6;
+ iov[4].iov_base = (PSTR)(PCSTR)hostname;
+ iov[4].iov_len = hostname.size();
+ iov[5].iov_base = (IOV_TYPE)":";
+ iov[5].iov_len = 1;
+ iov[6].iov_base = szTcpPort;
+ iov[6].iov_len = strlen(szTcpPort);
+ iov[7].iov_base = (IOV_TYPE)"\r\n\r\n";
+ iov[7].iov_len = 4;
+
+ if (peer_addr.set (tcpPort, (PCSTR)hostname) == -1)
+ {
+ return false;
+ }
+ else if (connector.connect (peer, peer_addr, &aceTimeout) == -1)
+ {
+ if (errno == ETIME)
+ {
+ }
+ return false;
+ }
+ else if (peer.sendv_n (iov, 8, &aceTimeout) == -1)
+ {
+ return false;
+ }
+
+ ssize_t numReceived = 0;
+#define BUFSIZE 4096
+ char buf [BUFSIZE];
+
+ CStdString header;
+ bool gotHeader = false;
+ while ( (numReceived = peer.recv (buf, BUFSIZE, &aceTimeout)) > 0 )
+ {
+ for(int i=0; i<numReceived; i++)
+ {
+ if(!gotHeader)
+ {
+ // extract header (delimited by CR-LF-CR-LF)
+ header += buf[i];
+ size_t headerSize = header.size();
+ if (headerSize > 4 &&
+ header.GetAt(headerSize-1) == '\n' &&
+ header.GetAt(headerSize-2) == '\r' &&
+ header.GetAt(headerSize-3) == '\n' &&
+ header.GetAt(headerSize-4) == '\r' )
+ {
+ gotHeader = true;
+ }
+ }
+ else
+ {
+ // extract content
+ response += buf[i];
+ }
+ }
+ }
+ if(numReceived < 0)
+ {
+ return false;
+ }
+ if(header.size() <= 0 || response.size() <= 0)
+ {
+ return false;
+ }
+ if( header.GetAt(10) != '2' &&
+ header.GetAt(11) != '0' &&
+ header.GetAt(12) != '0' &&
+ header.GetAt(13) != ' ' &&
+ header.GetAt(14) != 'O' &&
+ header.GetAt(15) != 'K' )
+ {
+ return false;
+ }
+ return true;
+}
+
+bool OrkHttpSingleLineClient::Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout)
+{
+ CStdString requestString = "/" + serviceName + "/command?";
+ requestString += request.SerializeUrl();
+ CStdString responseString;
+ if (ExecuteUrl(requestString, responseString, hostname, tcpPort, timeout))
+ {
+ response.DeSerializeSingleLine(responseString);
+ return true;
+ }
+ return false;
+}
+
diff --git a/orkbasecxx/OrkClient.h b/orkbasecxx/OrkClient.h
new file mode 100644
index 0000000..26e59a1
--- /dev/null
+++ b/orkbasecxx/OrkClient.h
@@ -0,0 +1,43 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __ORKCLIENT_H__
+#define __ORKCLIENT_H__
+
+#include "messages/SyncMessage.h"
+#include "messages/AsyncMessage.h"
+
+/** Abstract base class for all clients. */
+class DLL_IMPORT_EXPORT OrkClient
+{
+public:
+ virtual bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5) = 0;
+};
+
+/** Abstract base class for all clients based on http. */
+class DLL_IMPORT_EXPORT OrkHttpClient : public OrkClient
+{
+public:
+ virtual bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5) = 0;
+ bool ExecuteUrl(CStdString& request, CStdString& response, CStdString& hostname, int tcpPort, int timeout = 5);
+protected:
+};
+
+/** Client that uses a HTTP URL request and receives the response back in the SingleLine format. */
+class DLL_IMPORT_EXPORT OrkHttpSingleLineClient : public OrkHttpClient
+{
+public:
+ bool Execute(SyncMessage& request, AsyncMessage& response, CStdString& hostname, int tcpPort, CStdString& serviceName, int timeout = 5);
+};
+
+#endif
diff --git a/orkbasecxx/StdString.h b/orkbasecxx/StdString.h
new file mode 100644
index 0000000..0743e16
--- /dev/null
+++ b/orkbasecxx/StdString.h
@@ -0,0 +1,3747 @@
+#ifdef WIN32
+#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning
+#pragma warning( disable: 4018 ) // signed/unsigned mismatch
+#endif
+
+
+
+// =============================================================================
+// FILE: StdString.h
+// AUTHOR: Joe O'Leary (with outside help noted in comments)
+// REMARKS:
+// This header file declares the CStdStr template. This template derives
+// the Standard C++ Library basic_string<> template and add to it the
+// the following conveniences:
+// - The full MFC CString set of functions (including implicit cast)
+// - writing to/reading from COM IStream interfaces
+// - Functional objects for use in STL algorithms
+//
+// From this template, we intstantiate two classes: CStdStringA and
+// CStdStringW. The name "CStdString" is just a #define of one of these,
+// based upone the _UNICODE macro setting
+//
+// This header also declares our own version of the MFC/ATL UNICODE-MBCS
+// conversion macros. Our version looks exactly like the Microsoft's to
+// facilitate portability.
+//
+// NOTE:
+// If you you use this in an MFC or ATL build, you should include either
+// afx.h or atlbase.h first, as appropriate.
+//
+// PEOPLE WHO HAVE CONTRIBUTED TO THIS CLASS:
+//
+// Several people have helped me iron out problems and othewise improve
+// this class. OK, this is a long list but in my own defense, this code
+// has undergone two major rewrites. Many of the improvements became
+// necessary after I rewrote the code as a template. Others helped me
+// improve the CString facade.
+//
+// Anyway, these people are (in chronological order):
+//
+// - Pete the Plumber (???)
+// - Julian Selman
+// - Chris (of Melbsys)
+// - Dave Plummer
+// - John C Sipos
+// - Chris Sells
+// - Nigel Nunn
+// - Fan Xia
+// - Matthew Williams
+// - Carl Engman
+// - Mark Zeren
+// - Craig Watson
+// - Rich Zuris
+// - Karim Ratib
+// - Chris Conti
+// - Baptiste Lepilleur
+// - Greg Pickles
+// - Jim Cline
+// - Jeff Kohn
+// - Todd Heckel
+// - Ullrich Pollähne
+// - Joe Vitaterna
+// - Joe Woodbury
+// - Aaron (no last name)
+// - Joldakowski (???)
+// - Scott Hathaway
+// - Eric Nitzche
+// - Pablo Presedo
+// - Farrokh Nejadlotfi
+// - Jason Mills
+// - Igor Kholodov
+// - Mike Crusader
+// - John James
+// - Wang Haifeng
+// - Tim Dowty
+// - Arnt Witteveen
+// - Glen Maynard
+// - Paul DeMarco
+// - Bagira (full name?)
+// - Ronny Schulz
+// - Jakko Van Hunen
+// - Charles G
+//
+// REVISION HISTORY
+// 2003-JUL-10 - Thanks to Charles G for making me realize my 'FmtArg' fixes
+// had inadvertently broken the DLL-export code (which is
+// normally commented out. I had to move it up higher. Also
+// this helped me catch a bug in ssicoll that would prevent
+// compilation, otherwise.
+//
+// 2003-MAR-14 - Thanks to Jakko Van Hunen for pointing out a copy-and-paste
+// bug in one of the overloads of FmtArg.
+//
+// 2003-MAR-10 - Thanks to Ronny Schulz for (twice!) sending me some changes
+// to help CStdString build on SGI and for pointing out an
+// error in placement of my preprocessor macros for ssfmtmsg.
+//
+// 2002-NOV-26 - Thanks to Bagira for pointing out that my implementation of
+// SpanExcluding was not properly handling the case in which
+// the string did NOT contain any of the given characters
+//
+// 2002-OCT-21 - Many thanks to Paul DeMarco who was invaluable in helping me
+// get this code working with Borland's free compiler as well
+// as the Dev-C++ compiler (available free at SourceForge).
+//
+// 2002-SEP-13 - Thanks to Glen Maynard who helped me get rid of some loud
+// but harmless warnings that were showing up on g++. Glen
+// also pointed out that some pre-declarations of FmtArg<>
+// specializations were unnecessary (and no good on G++)
+//
+// 2002-JUN-26 - Thanks to Arnt Witteveen for pointing out that I was using
+// static_cast<> in a place in which I should have been using
+// reinterpret_cast<> (the ctor for unsigned char strings).
+// That's what happens when I don't unit-test properly!
+// Arnt also noticed that CString was silently correcting the
+// 'nCount' argument to Left() and Right() where CStdString was
+// not (and crashing if it was bad). That is also now fixed!
+//
+// 2002-FEB-25 - Thanks to Tim Dowty for pointing out (and giving me the fix
+// for) a conversion problem with non-ASCII MBCS characters.
+// CStdString is now used in my favorite commercial MP3 player!
+//
+// 2001-DEC-06 - Thanks to Wang Haifeng for spotting a problem in one of the
+// assignment operators (for _bstr_t) that would cause compiler
+// errors when refcounting protection was turned off.
+//
+// 2001-NOV-27 - Remove calls to operator!= which involve reverse_iterators
+// due to a conflict with the rel_ops operator!=. Thanks to
+// John James for pointing this out.
+//
+// 2001-OCT-29 - Added a minor range checking fix for the Mid function to
+// make it as forgiving as CString's version is. Thanks to
+// Igor Kholodov for noticing this.
+// - Added a specialization of std::swap for CStdString. Thanks
+// to Mike Crusader for suggesting this! It's commented out
+// because you're not supposed to inject your own code into the
+// 'std' namespace. But if you don't care about that, it's
+// there if you want it
+// - Thanks to Jason Mills for catching a case where CString was
+// more forgiving in the Delete() function than I was.
+//
+// 2001-JUN-06 - I was violating the Standard name lookup rules stated
+// in [14.6.2(3)]. None of the compilers I've tried so
+// far apparently caught this but HP-UX aCC 3.30 did. The
+// fix was to add 'this->' prefixes in many places.
+// Thanks to Farrokh Nejadlotfi for this!
+//
+// 2001-APR-27 - StreamLoad was calculating the number of BYTES in one
+// case, not characters. Thanks to Pablo Presedo for this.
+//
+// 2001-FEB-23 - Replace() had a bug which caused infinite loops if the
+// source string was empty. Fixed thanks to Eric Nitzsche.
+//
+// 2001-FEB-23 - Scott Hathaway was a huge help in providing me with the
+// ability to build CStdString on Sun Unix systems. He
+// sent me detailed build reports about what works and what
+// does not. If CStdString compiles on your Unix box, you
+// can thank Scott for it.
+//
+// 2000-DEC-29 - Joldakowski noticed one overload of Insert failed to do a
+// range check as CString's does. Now fixed -- thanks!
+//
+// 2000-NOV-07 - Aaron pointed out that I was calling static member
+// functions of char_traits via a temporary. This was not
+// technically wrong, but it was unnecessary and caused
+// problems for poor old buggy VC5. Thanks Aaron!
+//
+// 2000-JUL-11 - Joe Woodbury noted that the CString::Find docs don't match
+// what the CString::Find code really ends up doing. I was
+// trying to match the docs. Now I match the CString code
+// - Joe also caught me truncating strings for GetBuffer() calls
+// when the supplied length was less than the current length.
+//
+// 2000-MAY-25 - Better support for STLPORT's Standard library distribution
+// - Got rid of the NSP macro - it interfered with Koenig lookup
+// - Thanks to Joe Woodbury for catching a TrimLeft() bug that
+// I introduced in January. Empty strings were not getting
+// trimmed
+//
+// 2000-APR-17 - Thanks to Joe Vitaterna for pointing out that ReverseFind
+// is supposed to be a const function.
+//
+// 2000-MAR-07 - Thanks to Ullrich Pollähne for catching a range bug in one
+// of the overloads of assign.
+//
+// 2000-FEB-01 - You can now use CStdString on the Mac with CodeWarrior!
+// Thanks to Todd Heckel for helping out with this.
+//
+// 2000-JAN-23 - Thanks to Jim Cline for pointing out how I could make the
+// Trim() function more efficient.
+// - Thanks to Jeff Kohn for prompting me to find and fix a typo
+// in one of the addition operators that takes _bstr_t.
+// - Got rid of the .CPP file - you only need StdString.h now!
+//
+// 1999-DEC-22 - Thanks to Greg Pickles for helping me identify a problem
+// with my implementation of CStdString::FormatV in which
+// resulting string might not be properly NULL terminated.
+//
+// 1999-DEC-06 - Chris Conti pointed yet another basic_string<> assignment
+// bug that MS has not fixed. CStdString did nothing to fix
+// it either but it does now! The bug was: create a string
+// longer than 31 characters, get a pointer to it (via c_str())
+// and then assign that pointer to the original string object.
+// The resulting string would be empty. Not with CStdString!
+//
+// 1999-OCT-06 - BufferSet was erasing the string even when it was merely
+// supposed to shrink it. Fixed. Thanks to Chris Conti.
+// - Some of the Q172398 fixes were not checking for assignment-
+// to-self. Fixed. Thanks to Baptiste Lepilleur.
+//
+// 1999-AUG-20 - Improved Load() function to be more efficient by using
+// SizeOfResource(). Thanks to Rich Zuris for this.
+// - Corrected resource ID constructor, again thanks to Rich.
+// - Fixed a bug that occurred with UNICODE characters above
+// the first 255 ANSI ones. Thanks to Craig Watson.
+// - Added missing overloads of TrimLeft() and TrimRight().
+// Thanks to Karim Ratib for pointing them out
+//
+// 1999-JUL-21 - Made all calls to GetBuf() with no args check length first.
+//
+// 1999-JUL-10 - Improved MFC/ATL independence of conversion macros
+// - Added SS_NO_REFCOUNT macro to allow you to disable any
+// reference-counting your basic_string<> impl. may do.
+// - Improved ReleaseBuffer() to be as forgiving as CString.
+// Thanks for Fan Xia for helping me find this and to
+// Matthew Williams for pointing it out directly.
+//
+// 1999-JUL-06 - Thanks to Nigel Nunn for catching a very sneaky bug in
+// ToLower/ToUpper. They should call GetBuf() instead of
+// data() in order to ensure the changed string buffer is not
+// reference-counted (in those implementations that refcount).
+//
+// 1999-JUL-01 - Added a true CString facade. Now you can use CStdString as
+// a drop-in replacement for CString. If you find this useful,
+// you can thank Chris Sells for finally convincing me to give
+// in and implement it.
+// - Changed operators << and >> (for MFC CArchive) to serialize
+// EXACTLY as CString's do. So now you can send a CString out
+// to a CArchive and later read it in as a CStdString. I have
+// no idea why you would want to do this but you can.
+//
+// 1999-JUN-21 - Changed the CStdString class into the CStdStr template.
+// - Fixed FormatV() to correctly decrement the loop counter.
+// This was harmless bug but a bug nevertheless. Thanks to
+// Chris (of Melbsys) for pointing it out
+// - Changed Format() to try a normal stack-based array before
+// using to _alloca().
+// - Updated the text conversion macros to properly use code
+// pages and to fit in better in MFC/ATL builds. In other
+// words, I copied Microsoft's conversion stuff again.
+// - Added equivalents of CString::GetBuffer, GetBufferSetLength
+// - new sscpy() replacement of CStdString::CopyString()
+// - a Trim() function that combines TrimRight() and TrimLeft().
+//
+// 1999-MAR-13 - Corrected the "NotSpace" functional object to use _istpace()
+// instead of _isspace() Thanks to Dave Plummer for this.
+//
+// 1999-FEB-26 - Removed errant line (left over from testing) that #defined
+// _MFC_VER. Thanks to John C Sipos for noticing this.
+//
+// 1999-FEB-03 - Fixed a bug in a rarely-used overload of operator+() that
+// caused infinite recursion and stack overflow
+// - Added member functions to simplify the process of
+// persisting CStdStrings to/from DCOM IStream interfaces
+// - Added functional objects (e.g. StdStringLessNoCase) that
+// allow CStdStrings to be used as keys STL map objects with
+// case-insensitive comparison
+// - Added array indexing operators (i.e. operator[]). I
+// originally assumed that these were unnecessary and would be
+// inherited from basic_string. However, without them, Visual
+// C++ complains about ambiguous overloads when you try to use
+// them. Thanks to Julian Selman to pointing this out.
+//
+// 1998-FEB-?? - Added overloads of assign() function to completely account
+// for Q172398 bug. Thanks to "Pete the Plumber" for this
+//
+// 1998-FEB-?? - Initial submission
+//
+// COPYRIGHT:
+// 2002 Joseph M. O'Leary. This code is 100% free. Use it anywhere you
+// want. Rewrite it, restructure it, whatever. If you can write software
+// that makes money off of it, good for you. I kinda like capitalism.
+// Please don't blame me if it causes your $30 billion dollar satellite
+// explode in orbit. If you redistribute it in any form, I'd appreciate it
+// if you would leave this notice here.
+//
+// If you find any bugs, please let me know:
+//
+// jmoleary@earthlink.net
+// http://www.joeo.net
+//
+// The latest version of this code should always be available at the
+// following link:
+//
+// http://www.joeo.net/code/StdString.zip
+// =============================================================================
+
+// Avoid multiple inclusion the VC++ way,
+// Turn off browser references
+// Turn off unavoidable compiler warnings
+
+#if defined(_MSC_VER) && (_MSC_VER > 1100)
+ #pragma once
+ #pragma component(browser, off, references, "CStdString")
+ #pragma warning (disable : 4290) // C++ Exception Specification ignored
+ #pragma warning (disable : 4127) // Conditional expression is constant
+ #pragma warning (disable : 4097) // typedef name used as synonym for class name
+#endif
+
+// Borland warnings to turn off
+
+#ifdef __BORLANDC__
+ #pragma option push -w-inl
+// #pragma warn -inl // Turn off inline function warnings
+#endif
+
+#ifndef STDSTRING_H
+#define STDSTRING_H
+
+// MACRO: SS_UNSIGNED
+// ------------------
+// This macro causes the addition of a constructor and assignment operator
+// which take unsigned characters. CString has such functions and in order
+// to provide maximum CString-compatability, this code needs them as well.
+// In practice you will likely never need these functions...
+
+//#define SS_UNSIGNED
+
+#ifdef SS_ALLOW_UNSIGNED_CHARS
+ #define SS_UNSIGNED
+#endif
+
+// MACRO: SS_SAFE_FORMAT
+// ---------------------
+// This macro provides limited compatability with a questionable CString
+// "feature". You can define it in order to avoid a common problem that
+// people encounter when switching from CString to CStdString.
+//
+// To illustrate the problem -- With CString, you can do this:
+//
+// CString sName("Joe");
+// CString sTmp;
+// sTmp.Format("My name is %s", sName); // WORKS!
+//
+// However if you were to try this with CStdString, your program would
+// crash.
+//
+// CStdString sName("Joe");
+// CStdString sTmp;
+// sTmp.Format("My name is %s", sName); // CRASHES!
+//
+// You must explicitly call c_str() or cast the object to the proper type
+//
+// sTmp.Format("My name is %s", sName.c_str()); // WORKS!
+// sTmp.Format("My name is %s", static_cast<PCSTR>(sName));// WORKS!
+// sTmp.Format("My name is %s", (PCSTR)sName);// WORKS!
+//
+// This is because it is illegal to pass anything but a POD type as a
+// variadic argument to a variadic function (i.e. as one of the "..."
+// arguments). The type const char* is a POD type. The type CStdString
+// is not. Of course, neither is the type CString, but CString lets you do
+// it anyway due to the way they laid out the class in binary. I have no
+// control over this in CStdString since I derive from whatever
+// implementation of basic_string is available.
+//
+// However if you have legacy code (which does this) that you want to take
+// out of the MFC world and you don't want to rewrite all your calls to
+// Format(), then you can define this flag and it will no longer crash.
+//
+// Note however that this ONLY works for Format(), not sprintf, fprintf,
+// etc. If you pass a CStdString object to one of those functions, your
+// program will crash. Not much I can do to get around this, short of
+// writing substitutes for those functions as well.
+
+#define SS_SAFE_FORMAT // use new template style Format() function
+
+
+// MACRO: SS_NO_IMPLICIT_CAST
+// --------------------------
+// Some people don't like the implicit cast to const char* (or rather to
+// const CT*) that CStdString (and MFC's CString) provide. That was the
+// whole reason I created this class in the first place, but hey, whatever
+// bakes your cake. Just #define this macro to get rid of the the implicit
+// cast.
+
+//#define SS_NO_IMPLICIT_CAST // gets rid of operator const CT*()
+
+
+// MACRO: SS_NO_REFCOUNT
+// ---------------------
+// turns off reference counting at the assignment level. Only needed
+// for the version of basic_string<> that comes with Visual C++ versions
+// 6.0 or earlier, and only then in some heavily multithreaded scenarios.
+// Uncomment it if you feel you need it.
+
+#define SS_NO_REFCOUNT
+
+// MACRO: SS_WIN32
+// ---------------
+// When this flag is set, we are building code for the Win32 platform and
+// may use Win32 specific functions (such as LoadString). This gives us
+// a couple of nice extras for the code.
+//
+// Obviously, Microsoft's is not the only compiler available for Win32 out
+// there. So I can't just check to see if _MSC_VER is defined to detect
+// if I'm building on Win32. So for now, if you use MS Visual C++ or
+// Borland's compiler, I turn this on. Otherwise you may turn it on
+// yourself, if you prefer
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WIN32)
+ #define SS_WIN32
+#endif
+
+// MACRO: SS_ANSI
+// --------------
+// When this macro is defined, the code attempts only to use ANSI/ISO
+// standard library functions to do it's work. It will NOT attempt to use
+// any Win32 of Visual C++ specific functions -- even if they are
+// available. You may define this flag yourself to prevent any Win32
+// of VC++ specific functions from being called.
+
+// If we're not on Win32, we MUST use an ANSI build
+
+#ifndef SS_WIN32
+ #if !defined(SS_NO_ANSI)
+ #define SS_ANSI
+ #endif
+#endif
+
+// MACRO: SS_ALLOCA
+// ----------------
+// Some implementations of the Standard C Library have a non-standard
+// function known as alloca(). This functions allows one to allocate a
+// variable amount of memory on the stack. It comes in very useful for
+// the ASCII/MBCS conversion macros.
+//
+// Here we attempt to determine automatically if alloca() is available on
+// this platform. If so we define SS_ALLOCA to be the name of the alloca
+// function. If SS_ALLOCA is undefined later on, then the conversion
+// macros will not be compiled.
+//
+// You may prevent SS_ALLOCA
+
+
+
+// Avoid legacy code screw up: if _UNICODE is defined, UNICODE must be as well
+
+#if defined (_UNICODE) && !defined (UNICODE)
+ #define UNICODE
+#endif
+#if defined (UNICODE) && !defined (_UNICODE)
+ #define _UNICODE
+#endif
+
+// -----------------------------------------------------------------------------
+// MIN and MAX. The Standard C++ template versions go by so many names (at
+// at least in the MS implementation) that you never know what's available
+// -----------------------------------------------------------------------------
+template<class Type>
+inline const Type& SSMIN(const Type& arg1, const Type& arg2)
+{
+ return arg2 < arg1 ? arg2 : arg1;
+}
+template<class Type>
+inline const Type& SSMAX(const Type& arg1, const Type& arg2)
+{
+ return arg2 > arg1 ? arg2 : arg1;
+}
+
+// If they have not #included W32Base.h (part of my W32 utility library) then
+// we need to define some stuff. Otherwise, this is all defined there.
+
+#if !defined(W32BASE_H)
+
+ // If they want us to use only standard C++ stuff (no Win32 stuff)
+
+ #ifdef SS_ANSI
+
+ // On Win32 we have TCHAR.H so just include it. This is NOT violating
+ // the spirit of SS_ANSI as we are not calling any Win32 functions here.
+
+ #ifdef SS_WIN32
+
+ #include <TCHAR.H>
+ #include <WTYPES.H>
+ #ifndef STRICT
+ #define STRICT
+ #endif
+
+ // ... but on non-Win32 platforms, we must #define the types we need.
+
+ #else
+
+ typedef const char* PCSTR;
+ typedef char* PSTR;
+ typedef const wchar_t* PCWSTR;
+ typedef wchar_t* PWSTR;
+ #ifdef UNICODE
+ typedef wchar_t TCHAR;
+ #else
+ typedef char TCHAR;
+ #endif
+ typedef wchar_t OLECHAR;
+
+ #endif // #ifndef _WIN32
+
+
+ // Make sure ASSERT and verify are defined using only ANSI stuff
+
+ #ifndef ASSERT
+ #include <assert.h>
+ #define ASSERT(f) assert((f))
+ #endif
+ #ifndef VERIFY
+ #ifdef _DEBUG
+ #define VERIFY(x) ASSERT((x))
+ #else
+ #define VERIFY(x) x
+ #endif
+ #endif
+
+ #else // ...else SS_ANSI is NOT defined
+
+ #include <TCHAR.H>
+ #include <WTYPES.H>
+ #ifndef STRICT
+ #define STRICT
+ #endif
+
+ // Make sure ASSERT and verify are defined
+
+ #ifndef ASSERT
+ #include <crtdbg.h>
+ #define ASSERT(f) _ASSERTE((f))
+ #endif
+ #ifndef VERIFY
+ #ifdef _DEBUG
+ #define VERIFY(x) ASSERT((x))
+ #else
+ #define VERIFY(x) x
+ #endif
+ #endif
+
+ #endif // #ifdef SS_ANSI
+
+ #ifndef UNUSED
+ #define UNUSED(x) x
+ #endif
+
+#endif // #ifndef W32BASE_H
+
+// Standard headers needed
+
+#include <string> // basic_string
+#include <algorithm> // for_each, etc.
+#include <functional> // for StdStringLessNoCase, et al
+#include <locale> // for various facets
+
+// If this is a recent enough version of VC include comdef.h, so we can write
+// member functions to deal with COM types & compiler support classes e.g. _bstr_t
+
+#if defined (_MSC_VER) && (_MSC_VER >= 1100)
+ #include <comdef.h>
+ #define SS_INC_COMDEF // signal that we #included MS comdef.h file
+ #define STDSTRING_INC_COMDEF
+ #define SS_NOTHROW __declspec(nothrow)
+#else
+ #define SS_NOTHROW
+#endif
+
+#ifndef TRACE
+ #define TRACE_DEFINED_HERE
+ #define TRACE
+#endif
+
+// Microsoft defines PCSTR, PCWSTR, etc, but no PCTSTR. I hate to use the
+// versions with the "L" in front of them because that's a leftover from Win 16
+// days, even though it evaluates to the same thing. Therefore, Define a PCSTR
+// as an LPCTSTR.
+
+#if !defined(PCTSTR) && !defined(PCTSTR_DEFINED)
+ typedef const TCHAR* PCTSTR;
+ #define PCTSTR_DEFINED
+#endif
+
+#if !defined(PCOLESTR) && !defined(PCOLESTR_DEFINED)
+ typedef const OLECHAR* PCOLESTR;
+ #define PCOLESTR_DEFINED
+#endif
+
+#if !defined(POLESTR) && !defined(POLESTR_DEFINED)
+ typedef OLECHAR* POLESTR;
+ #define POLESTR_DEFINED
+#endif
+
+#if !defined(PCUSTR) && !defined(PCUSTR_DEFINED)
+ typedef const unsigned char* PCUSTR;
+ typedef unsigned char* PUSTR;
+ #define PCUSTR_DEFINED
+#endif
+
+
+// SGI compiler 7.3 doesnt know these types - oh and btw, remember to use
+// -LANG:std in the CXX Flags
+#if defined(__sgi)
+ typedef unsigned long DWORD;
+ typedef void * LPCVOID;
+#endif
+
+
+// SS_USE_FACET macro and why we need it:
+//
+// Since I'm a good little Standard C++ programmer, I use locales. Thus, I
+// need to make use of the use_facet<> template function here. Unfortunately,
+// this need is complicated by the fact the MS' implementation of the Standard
+// C++ Library has a non-standard version of use_facet that takes more
+// arguments than the standard dictates. Since I'm trying to write CStdString
+// to work with any version of the Standard library, this presents a problem.
+//
+// The upshot of this is that I can't do 'use_facet' directly. The MS' docs
+// tell me that I have to use a macro, _USE() instead. Since _USE obviously
+// won't be available in other implementations, this means that I have to write
+// my OWN macro -- SS_USE_FACET -- that evaluates either to _USE or to the
+// standard, use_facet.
+//
+// If you are having trouble with the SS_USE_FACET macro, in your implementation
+// of the Standard C++ Library, you can define your own version of SS_USE_FACET.
+#ifndef schMSG
+ #define schSTR(x) #x
+ #define schSTR2(x) schSTR(x)
+ #define schMSG(desc) message(__FILE__ "(" schSTR2(__LINE__) "):" #desc)
+#endif
+
+#ifndef SS_USE_FACET
+ // STLPort #defines a macro (__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) for
+ // all MSVC builds, erroneously in my opinion. It causes problems for
+ // my SS_ANSI builds. In my code, I always comment out that line. You'll
+ // find it in \stlport\config\stl_msvc.h
+ #if defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= 0x400 )
+ #if defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && defined(_MSC_VER)
+ #ifdef SS_ANSI
+ #pragma schMSG(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS defined!!)
+ #endif
+ #endif
+ #define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
+ #elif defined(_MSC_VER )
+ #define SS_USE_FACET(loc, fac) std::_USE(loc, fac)
+
+ // ...and
+ #elif defined(_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE)
+ #define SS_USE_FACET(loc, fac) std::use_facet(loc, (fac*)0)
+ #else
+ #define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
+ #endif
+#endif
+
+// =============================================================================
+// UNICODE/MBCS conversion macros. Made to work just like the MFC/ATL ones.
+// =============================================================================
+
+#include <wchar.h> // Added to Std Library with Amendment #1.
+
+// First define the conversion helper functions. We define these regardless of
+// any preprocessor macro settings since their names won't collide.
+
+// Not sure if we need all these headers. I believe ANSI says we do.
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <wctype.h>
+#include <ctype.h>
+#include <stdlib.h>
+#ifndef va_start
+ #include <varargs.h>
+#endif
+
+// StdCodeCvt - made to look like Win32 functions WideCharToMultiByte
+// and MultiByteToWideChar but uses locales in SS_ANSI
+// builds
+
+#if defined (SS_ANSI) || !defined (SS_WIN32)
+
+ typedef std::codecvt<wchar_t, char, mbstate_t> SSCodeCvt;
+
+
+ inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars,
+ const std::locale& loc=std::locale())
+ {
+ ASSERT(0 != pA);
+ ASSERT(0 != pW);
+ pW[0] = '\0';
+ PCSTR pBadA = 0;
+ PWSTR pBadW = 0;
+ SSCodeCvt::result res = SSCodeCvt::ok;
+ const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);
+ SSCodeCvt::state_type st= { 0 };
+ res = conv.in(st,
+ pA, pA + nChars, pBadA,
+ pW, pW + nChars, pBadW);
+ ASSERT(SSCodeCvt::ok == res);
+ return pW;
+ }
+ inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars,
+ const std::locale& loc=std::locale())
+ {
+ return StdCodeCvt(pW, (PCSTR)pA, nChars, loc);
+ }
+
+ inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars,
+ const std::locale& loc=std::locale())
+ {
+ ASSERT(0 != pA);
+ ASSERT(0 != pW);
+ pA[0] = '\0';
+ PSTR pBadA = 0;
+ PCWSTR pBadW = 0;
+ SSCodeCvt::result res = SSCodeCvt::ok;
+ const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);
+ SSCodeCvt::state_type st= { 0 };
+ res = conv.out(st,
+ pW, pW + nChars, pBadW,
+ pA, pA + nChars, pBadA);
+ ASSERT(SSCodeCvt::ok == res);
+ return pA;
+ }
+ inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars,
+ const std::locale& loc=std::locale())
+ {
+ return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, loc);
+ }
+
+#else // ...or are we doing things assuming win32 and Visual C++?
+
+ #include <malloc.h> // needed for _alloca
+
+ inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars, UINT acp=CP_ACP)
+ {
+ ASSERT(0 != pA);
+ ASSERT(0 != pW);
+ pW[0] = '\0';
+ MultiByteToWideChar(acp, 0, pA, -1, pW, nChars);
+ return pW;
+ }
+ inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars, UINT acp=CP_ACP)
+ {
+ return StdCodeCvt(pW, (PCSTR)pA, nChars, acp);
+ }
+
+ inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)
+ {
+ ASSERT(0 != pA);
+ ASSERT(0 != pW);
+ pA[0] = '\0';
+ WideCharToMultiByte(acp, 0, pW, -1, pA, nChars, 0, 0);
+ return pA;
+ }
+ inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)
+ {
+ return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, acp);
+ }
+
+#endif
+// Unicode/MBCS conversion macros are only available on implementations of
+// the "C" library that have the non-standard _alloca function. As far as I
+// know that's only Microsoft's though I've hear that the function exits
+// elsewhere.
+
+#if defined(SS_ALLOCA) && !defined SS_NO_CONVERSION
+
+ #include <malloc.h> // needed for _alloca
+
+
+ // Define our conversion macros to look exactly like Microsoft's to
+ // facilitate using this stuff both with and without MFC/ATL
+
+ #ifdef _CONVERSION_USES_THREAD_LOCALE
+ #ifndef _DEBUG
+ #define SSCVT int _cvt; _cvt; UINT _acp=GetACP(); \
+ _acp; PCWSTR _pw; _pw; PCSTR _pa; _pa
+ #else
+ #define SSCVT int _cvt = 0; _cvt; UINT _acp=GetACP();\
+ _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa
+ #endif
+ #else
+ #ifndef _DEBUG
+ #define SSCVT int _cvt; _cvt; UINT _acp=CP_ACP; _acp;\
+ PCWSTR _pw; _pw; PCSTR _pa; _pa
+ #else
+ #define SSCVT int _cvt = 0; _cvt; UINT _acp=CP_ACP; \
+ _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa
+ #endif
+ #endif
+
+ #ifdef _CONVERSION_USES_THREAD_LOCALE
+ #define SSA2W(pa) (\
+ ((_pa = pa) == 0) ? 0 : (\
+ _cvt = (sslen(_pa)+1),\
+ StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt, _acp)))
+ #define SSW2A(pw) (\
+ ((_pw = pw) == 0) ? 0 : (\
+ _cvt = (sslen(_pw)+1)*2,\
+ StdW2AHelper((LPSTR) _alloca(_cvt), _pw, _cvt, _acp)))
+ #else
+ #define SSA2W(pa) (\
+ ((_pa = pa) == 0) ? 0 : (\
+ _cvt = (sslen(_pa)+1),\
+ StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt)))
+ #define SSW2A(pw) (\
+ ((_pw = pw) == 0) ? 0 : (\
+ _cvt = (sslen(_pw)+1)*2,\
+ StdCodeCvt((LPSTR) _alloca(_cvt), _pw, _cvt)))
+ #endif
+
+ #define SSA2CW(pa) ((PCWSTR)SSA2W((pa)))
+ #define SSW2CA(pw) ((PCSTR)SSW2A((pw)))
+
+ #ifdef UNICODE
+ #define SST2A SSW2A
+ #define SSA2T SSA2W
+ #define SST2CA SSW2CA
+ #define SSA2CT SSA2CW
+ inline PWSTR SST2W(PTSTR p) { return p; }
+ inline PTSTR SSW2T(PWSTR p) { return p; }
+ inline PCWSTR SST2CW(PCTSTR p) { return p; }
+ inline PCTSTR SSW2CT(PCWSTR p) { return p; }
+ #else
+ #define SST2W SSA2W
+ #define SSW2T SSW2A
+ #define SST2CW SSA2CW
+ #define SSW2CT SSW2CA
+ inline PSTR SST2A(PTSTR p) { return p; }
+ inline PTSTR SSA2T(PSTR p) { return p; }
+ inline PCSTR SST2CA(PCTSTR p) { return p; }
+ inline PCTSTR SSA2CT(PCSTR p) { return p; }
+ #endif // #ifdef UNICODE
+
+ #if defined(UNICODE)
+ // in these cases the default (TCHAR) is the same as OLECHAR
+ inline PCOLESTR SST2COLE(PCTSTR p) { return p; }
+ inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; }
+ inline POLESTR SST2OLE(PTSTR p) { return p; }
+ inline PTSTR SSOLE2T(POLESTR p) { return p; }
+ #elif defined(OLE2ANSI)
+ // in these cases the default (TCHAR) is the same as OLECHAR
+ inline PCOLESTR SST2COLE(PCTSTR p) { return p; }
+ inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; }
+ inline POLESTR SST2OLE(PTSTR p) { return p; }
+ inline PTSTR SSOLE2T(POLESTR p) { return p; }
+ #else
+ //CharNextW doesn't work on Win95 so we use this
+ #define SST2COLE(pa) SSA2CW((pa))
+ #define SST2OLE(pa) SSA2W((pa))
+ #define SSOLE2CT(po) SSW2CA((po))
+ #define SSOLE2T(po) SSW2A((po))
+ #endif
+
+ #ifdef OLE2ANSI
+ #define SSW2OLE SSW2A
+ #define SSOLE2W SSA2W
+ #define SSW2COLE SSW2CA
+ #define SSOLE2CW SSA2CW
+ inline POLESTR SSA2OLE(PSTR p) { return p; }
+ inline PSTR SSOLE2A(POLESTR p) { return p; }
+ inline PCOLESTR SSA2COLE(PCSTR p) { return p; }
+ inline PCSTR SSOLE2CA(PCOLESTR p){ return p; }
+ #else
+ #define SSA2OLE SSA2W
+ #define SSOLE2A SSW2A
+ #define SSA2COLE SSA2CW
+ #define SSOLE2CA SSW2CA
+ inline POLESTR SSW2OLE(PWSTR p) { return p; }
+ inline PWSTR SSOLE2W(POLESTR p) { return p; }
+ inline PCOLESTR SSW2COLE(PCWSTR p) { return p; }
+ inline PCWSTR SSOLE2CW(PCOLESTR p){ return p; }
+ #endif
+
+ // Above we've defined macros that look like MS' but all have
+ // an 'SS' prefix. Now we need the real macros. We'll either
+ // get them from the macros above or from MFC/ATL.
+
+ #if defined (USES_CONVERSION)
+
+ #define _NO_STDCONVERSION // just to be consistent
+
+ #else
+
+ #ifdef _MFC_VER
+
+ #include <afxconv.h>
+ #define _NO_STDCONVERSION // just to be consistent
+
+ #else
+
+ #define USES_CONVERSION SSCVT
+ #define A2CW SSA2CW
+ #define W2CA SSW2CA
+ #define T2A SST2A
+ #define A2T SSA2T
+ #define T2W SST2W
+ #define W2T SSW2T
+ #define T2CA SST2CA
+ #define A2CT SSA2CT
+ #define T2CW SST2CW
+ #define W2CT SSW2CT
+ #define ocslen sslen
+ #define ocscpy sscpy
+ #define T2COLE SST2COLE
+ #define OLE2CT SSOLE2CT
+ #define T2OLE SST2COLE
+ #define OLE2T SSOLE2CT
+ #define A2OLE SSA2OLE
+ #define OLE2A SSOLE2A
+ #define W2OLE SSW2OLE
+ #define OLE2W SSOLE2W
+ #define A2COLE SSA2COLE
+ #define OLE2CA SSOLE2CA
+ #define W2COLE SSW2COLE
+ #define OLE2CW SSOLE2CW
+
+ #endif // #ifdef _MFC_VER
+ #endif // #ifndef USES_CONVERSION
+#endif // #ifndef SS_NO_CONVERSION
+
+// Define ostring - generic name for std::basic_string<OLECHAR>
+
+#if !defined(ostring) && !defined(OSTRING_DEFINED)
+ typedef std::basic_string<OLECHAR> ostring;
+ #define OSTRING_DEFINED
+#endif
+
+// StdCodeCvt when there's no conversion to be done
+inline PSTR StdCodeCvt(PSTR pDst, PCSTR pSrc, int nChars)
+{
+ if ( nChars > 0 )
+ {
+ pDst[0] = '\0';
+ std::basic_string<char>::traits_type::copy(pDst, pSrc, nChars);
+// std::char_traits<char>::copy(pDst, pSrc, nChars);
+ if ( nChars > 0 )
+ pDst[nChars] = '\0';
+ }
+
+ return pDst;
+}
+inline PSTR StdCodeCvt(PSTR pDst, PCUSTR pSrc, int nChars)
+{
+ return StdCodeCvt(pDst, (PCSTR)pSrc, nChars);
+}
+inline PUSTR StdCodeCvt(PUSTR pDst, PCSTR pSrc, int nChars)
+{
+ return (PUSTR)StdCodeCvt((PSTR)pDst, pSrc, nChars);
+}
+
+inline PWSTR StdCodeCvt(PWSTR pDst, PCWSTR pSrc, int nChars)
+{
+ if ( nChars > 0 )
+ {
+ pDst[0] = '\0';
+ std::basic_string<wchar_t>::traits_type::copy(pDst, pSrc, nChars);
+// std::char_traits<wchar_t>::copy(pDst, pSrc, nChars);
+ if ( nChars > 0 )
+ pDst[nChars] = '\0';
+ }
+
+ return pDst;
+}
+
+
+// Define tstring -- generic name for std::basic_string<TCHAR>
+
+#if !defined(tstring) && !defined(TSTRING_DEFINED)
+ typedef std::basic_string<TCHAR> tstring;
+ #define TSTRING_DEFINED
+#endif
+
+// a very shorthand way of applying the fix for KB problem Q172398
+// (basic_string assignment bug)
+
+#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )
+ #define Q172398(x) (x).erase()
+#else
+ #define Q172398(x)
+#endif
+
+// =============================================================================
+// INLINE FUNCTIONS ON WHICH CSTDSTRING RELIES
+//
+// Usually for generic text mapping, we rely on preprocessor macro definitions
+// to map to string functions. However the CStdStr<> template cannot use
+// macro-based generic text mappings because its character types do not get
+// resolved until template processing which comes AFTER macro processing. In
+// other words, UNICODE is of little help to us in the CStdStr template
+//
+// Therefore, to keep the CStdStr declaration simple, we have these inline
+// functions. The template calls them often. Since they are inline (and NOT
+// exported when this is built as a DLL), they will probably be resolved away
+// to nothing.
+//
+// Without these functions, the CStdStr<> template would probably have to broken
+// out into two, almost identical classes. Either that or it would be a huge,
+// convoluted mess, with tons of "if" statements all over the place checking the
+// size of template parameter CT.
+//
+// In several cases, you will see two versions of each function. One version is
+// the more portable, standard way of doing things, while the other is the
+// non-standard, but often significantly faster Visual C++ way.
+// =============================================================================
+
+// If they defined SS_NO_REFCOUNT, then we must convert all assignments
+
+#ifdef SS_NO_REFCOUNT
+ #define SSREF(x) (x).c_str()
+#else
+ #define SSREF(x) (x)
+#endif
+
+// -----------------------------------------------------------------------------
+// sslen: strlen/wcslen wrappers
+// -----------------------------------------------------------------------------
+template<typename CT> inline int sslen(const CT* pT)
+{
+ return 0 == pT ? 0 : std::basic_string<CT>::traits_type::length(pT);
+// return 0 == pT ? 0 : std::char_traits<CT>::length(pT);
+}
+inline SS_NOTHROW int sslen(const std::string& s)
+{
+ return s.length();
+}
+inline SS_NOTHROW int sslen(const std::wstring& s)
+{
+ return s.length();
+}
+
+// -----------------------------------------------------------------------------
+// sstolower/sstoupper -- convert characters to upper/lower case
+// -----------------------------------------------------------------------------
+template<typename CT>
+inline CT sstolower(const CT& t, const std::locale& loc = std::locale())
+{
+ return std::tolower<CT>(t, loc);
+}
+template<typename CT>
+inline CT sstoupper(const CT& t, const std::locale& loc = std::locale())
+{
+ return std::toupper<CT>(t, loc);
+}
+
+// -----------------------------------------------------------------------------
+// ssasn: assignment functions -- assign "sSrc" to "sDst"
+// -----------------------------------------------------------------------------
+typedef std::string::size_type SS_SIZETYPE; // just for shorthand, really
+typedef std::string::pointer SS_PTRTYPE;
+typedef std::wstring::size_type SW_SIZETYPE;
+typedef std::wstring::pointer SW_PTRTYPE;
+
+inline void ssasn(std::string& sDst, const std::string& sSrc)
+{
+ if ( sDst.c_str() != sSrc.c_str() )
+ {
+ sDst.erase();
+ sDst.assign(SSREF(sSrc));
+ }
+}
+inline void ssasn(std::string& sDst, PCSTR pA)
+{
+ // Watch out for NULLs, as always.
+
+ if ( 0 == pA )
+ {
+ sDst.erase();
+ }
+
+ // If pA actually points to part of sDst, we must NOT erase(), but
+ // rather take a substring
+
+ else if ( pA >= sDst.c_str() && pA <= sDst.c_str() + sDst.size() )
+ {
+ sDst =sDst.substr(static_cast<SS_SIZETYPE>(pA-sDst.c_str()));
+ }
+
+ // Otherwise (most cases) apply the assignment bug fix, if applicable
+ // and do the assignment
+
+ else
+ {
+ Q172398(sDst);
+ sDst.assign(pA);
+ }
+}
+inline void ssasn(std::string& sDst, const std::wstring& sSrc)
+{
+ int nLen = sSrc.size();
+ sDst.resize(nLen * sizeof(wchar_t) + 1);
+ StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);
+ sDst.resize(nLen);
+ //sDst.resize(sslen(sDst.c_str()));
+}
+inline void ssasn(std::string& sDst, PCWSTR pW)
+{
+ int nLen = sslen(pW);
+ sDst.resize(nLen * sizeof(wchar_t) + 1);
+ StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), pW, nLen);
+ sDst.resize(nLen);
+ //sDst.resize(sslen(sDst.c_str()));
+}
+inline void ssasn(std::string& sDst, const int nNull)
+{
+ UNUSED(nNull);
+ ASSERT(nNull==0);
+ sDst.assign("");
+}
+inline void ssasn(std::wstring& sDst, const std::wstring& sSrc)
+{
+ if ( sDst.c_str() != sSrc.c_str() )
+ {
+ sDst.erase();
+ sDst.assign(SSREF(sSrc));
+ }
+}
+inline void ssasn(std::wstring& sDst, PCWSTR pW)
+{
+ // Watch out for NULLs, as always.
+
+ if ( 0 == pW )
+ {
+ sDst.erase();
+ }
+
+ // If pW actually points to part of sDst, we must NOT erase(), but
+ // rather take a substring
+
+ else if ( pW >= sDst.c_str() && pW <= sDst.c_str() + sDst.size() )
+ {
+ sDst = sDst.substr(static_cast<SW_SIZETYPE>(pW-sDst.c_str()));
+ }
+
+ // Otherwise (most cases) apply the assignment bug fix, if applicable
+ // and do the assignment
+
+ else
+ {
+ Q172398(sDst);
+ sDst.assign(pW);
+ }
+}
+#undef StrSizeType
+inline void ssasn(std::wstring& sDst, const std::string& sSrc)
+{
+ int nLen = sSrc.size();
+ sDst.resize(nLen+1);
+ StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen+1);
+ sDst.resize(sslen(sDst.c_str()));
+}
+inline void ssasn(std::wstring& sDst, PCSTR pA)
+{
+ int nLen = sslen(pA);
+ sDst.resize(nLen+1);
+ StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), pA, nLen+1);
+ sDst.resize(sslen(sDst.c_str()));
+}
+inline void ssasn(std::wstring& sDst, const int nNull)
+{
+ UNUSED(nNull);
+ ASSERT(nNull==0);
+ sDst.assign(L"");
+}
+
+
+// -----------------------------------------------------------------------------
+// ssadd: string object concatenation -- add second argument to first
+// -----------------------------------------------------------------------------
+inline void ssadd(std::string& sDst, const std::wstring& sSrc)
+{
+ int nSrcLen = sSrc.size();
+ int nDstLen = sDst.size();
+ int nEndLen = nSrcLen + nDstLen;
+ sDst.resize(nEndLen + 1);
+ StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen);
+ sDst.resize(nEndLen);
+}
+inline void ssadd(std::string& sDst, const std::string& sSrc)
+{
+ if ( &sDst == &sSrc )
+ sDst.reserve(2*sDst.size());
+
+ sDst.append(sSrc.c_str());
+}
+inline void ssadd(std::string& sDst, PCWSTR pW)
+{
+ int nSrcLen = sslen(pW);
+ int nDstLen = sDst.size();
+ int nEndLen = nSrcLen + nDstLen;
+ sDst.resize(nEndLen + 1);
+ StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nDstLen), pW, nSrcLen+1);
+ sDst.resize(nEndLen);
+}
+inline void ssadd(std::string& sDst, PCSTR pA)
+{
+ if ( pA )
+ {
+ // If the string being added is our internal string or a part of our
+ // internal string, then we must NOT do any reallocation without
+ // first copying that string to another object (since we're using a
+ // direct pointer)
+
+ if ( pA >= sDst.c_str() && pA <= sDst.c_str()+sDst.length())
+ {
+ if ( sDst.capacity() <= sDst.size()+sslen(pA) )
+ sDst.append(std::string(pA));
+ else
+ sDst.append(pA);
+ }
+ else
+ {
+ sDst.append(pA);
+ }
+ }
+}
+inline void ssadd(std::wstring& sDst, const std::wstring& sSrc)
+{
+ if ( &sDst == &sSrc )
+ sDst.reserve(2*sDst.size());
+
+ sDst.append(sSrc.c_str());
+}
+inline void ssadd(std::wstring& sDst, const std::string& sSrc)
+{
+ int nSrcLen = sSrc.size();
+ int nDstLen = sDst.size();
+ int nEndLen = nSrcLen + nDstLen;
+ sDst.resize(nEndLen+1);
+ StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen+1);
+ sDst.resize(nEndLen);
+}
+inline void ssadd(std::wstring& sDst, PCSTR pA)
+{
+ int nSrcLen = sslen(pA);
+ int nDstLen = sDst.size();
+ int nEndLen = nSrcLen + nDstLen;
+ sDst.resize(nEndLen + 1);
+ StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nDstLen), pA, nSrcLen+1);
+ sDst.resize(nEndLen);
+}
+inline void ssadd(std::wstring& sDst, PCWSTR pW)
+{
+ if ( pW )
+ {
+ // If the string being added is our internal string or a part of our
+ // internal string, then we must NOT do any reallocation without
+ // first copying that string to another object (since we're using a
+ // direct pointer)
+
+ if ( pW >= sDst.c_str() && pW <= sDst.c_str()+sDst.length())
+ {
+ if ( sDst.capacity() <= sDst.size()+sslen(pW) )
+ sDst.append(std::wstring(pW));
+ else
+ sDst.append(pW);
+ }
+ else
+ {
+ sDst.append(pW);
+ }
+ }
+}
+
+
+// -----------------------------------------------------------------------------
+// ssicmp: comparison (case insensitive )
+// -----------------------------------------------------------------------------
+template<typename CT>
+inline int ssicmp(const CT* pA1, const CT* pA2)
+{
+ std::locale loc;
+ const std::ctype<CT>& ct = SS_USE_FACET(loc, std::ctype<CT>);
+ CT f;
+ CT l;
+
+ do
+ {
+ f = ct.tolower(*(pA1++));
+ l = ct.tolower(*(pA2++));
+ } while ( (f) && (f == l) );
+
+ return (int)(f - l);
+}
+
+// -----------------------------------------------------------------------------
+// ssupr/sslwr: Uppercase/Lowercase conversion functions
+// -----------------------------------------------------------------------------
+
+template<typename CT>
+inline void sslwr(CT* pT, size_t nLen)
+{
+ SS_USE_FACET(std::locale(), std::ctype<CT>).tolower(pT, pT+nLen);
+}
+template<typename CT>
+inline void ssupr(CT* pT, size_t nLen)
+{
+ SS_USE_FACET(std::locale(), std::ctype<CT>).toupper(pT, pT+nLen);
+}
+
+
+// -----------------------------------------------------------------------------
+// vsprintf/vswprintf or _vsnprintf/_vsnwprintf equivalents. In standard
+// builds we can't use _vsnprintf/_vsnwsprintf because they're MS extensions.
+// -----------------------------------------------------------------------------
+#if defined(SS_ANSI) || !defined(_MSC_VER)
+
+ // Borland's headers put some ANSI "C" functions in the 'std' namespace.
+ // Promote them to the global namespace so we can use them here.
+
+ #if defined(__BORLANDC__)
+ using std::vsprintf;
+ using std::vswprintf;
+ #endif
+
+ inline int ssvsprintf(PSTR pA, size_t /*nCount*/, PCSTR pFmtA, va_list vl)
+ {
+ return vsprintf(pA, pFmtA, vl);
+ }
+ inline int ssvsprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
+ {
+ // JMO: Some distributions of the "C" have a version of vswprintf that
+ // takes 3 arguments (e.g. Microsoft, Borland, GNU). Others have a
+ // version which takes 4 arguments (an extra "count" argument in the
+ // second position. The best stab I can take at this so far is that if
+ // you are NOT running with MS, Borland, or GNU, then I'll assume you
+ // have the version that takes 4 arguments.
+ //
+ // I'm sure that these checks don't catch every platform correctly so if
+ // you get compiler errors on one of the lines immediately below, it's
+ // probably because your implemntation takes a different number of
+ // arguments. You can comment out the offending line (and use the
+ // alternate version) or you can figure out what compiler flag to check
+ // and add that preprocessor check in. Regardless, if you get an error
+ // on these lines, I'd sure like to hear from you about it.
+ //
+ // Thanks to Ronny Schulz for the SGI-specific checks here.
+
+// #if !defined(__MWERKS__) && !defined(__SUNPRO_CC_COMPAT) && !defined(__SUNPRO_CC)
+ #if !defined(_MSC_VER) \
+ && !defined (__BORLANDC__) \
+ && !defined(__sgi)
+
+ return vswprintf(pW, nCount, pFmtW, vl);
+
+ // suddenly with the current SGI 7.3 compiler there is no such function as
+ // vswprintf and the substitute needs explicit casts to compile
+
+ #elif defined(__sgi)
+
+ nCount;
+ return vsprintf( (char *)pW, (char *)pFmtW, vl);
+
+ #else
+
+ nCount;
+ return vswprintf(pW, pFmtW, vl);
+
+ #endif
+
+ }
+#else
+ inline int ssnprintf(PSTR pA, size_t nCount, PCSTR pFmtA, va_list vl)
+ {
+ return _vsnprintf(pA, nCount, pFmtA, vl);
+ }
+ inline int ssnprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
+ {
+ return _vsnwprintf(pW, nCount, pFmtW, vl);
+ }
+#endif
+
+
+
+// -----------------------------------------------------------------------------
+// ssload: Type safe, overloaded ::LoadString wrappers
+// There is no equivalent of these in non-Win32-specific builds. However, I'm
+// thinking that with the message facet, there might eventually be one
+// -----------------------------------------------------------------------------
+#if defined (SS_WIN32) && !defined(SS_ANSI)
+ inline int ssload(HMODULE hInst, UINT uId, PSTR pBuf, int nMax)
+ {
+ return ::LoadStringA(hInst, uId, pBuf, nMax);
+ }
+ inline int ssload(HMODULE hInst, UINT uId, PWSTR pBuf, int nMax)
+ {
+ return ::LoadStringW(hInst, uId, pBuf, nMax);
+ }
+#endif
+
+
+// -----------------------------------------------------------------------------
+// sscoll/ssicoll: Collation wrappers
+// Note -- with MSVC I have reversed the arguments order here because the
+// functions appear to return the opposite of what they should
+// -----------------------------------------------------------------------------
+template <typename CT>
+inline int sscoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)
+{
+ const std::collate<CT>& coll =
+ SS_USE_FACET(std::locale(), std::collate<CT>);
+
+ return coll.compare(sz2, sz2+nLen2, sz1, sz1+nLen1);
+}
+template <typename CT>
+inline int ssicoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)
+{
+ const std::locale loc;
+ const std::collate<CT>& coll = SS_USE_FACET(loc, std::collate<CT>);
+
+ // Some implementations seem to have trouble using the collate<>
+ // facet typedefs so we'll just default to basic_string and hope
+ // that's what the collate facet uses (which it generally should)
+
+// std::collate<CT>::string_type s1(sz1);
+// std::collate<CT>::string_type s2(sz2);
+ const std::basic_string<CT> sEmpty;
+ std::basic_string<CT> s1(sz1 ? sz1 : sEmpty.c_str());
+ std::basic_string<CT> s2(sz2 ? sz2 : sEmpty.c_str());
+
+ sslwr(const_cast<CT*>(s1.c_str()), nLen1);
+ sslwr(const_cast<CT*>(s2.c_str()), nLen2);
+ return coll.compare(s2.c_str(), s2.c_str()+nLen2,
+ s1.c_str(), s1.c_str()+nLen1);
+}
+
+
+// -----------------------------------------------------------------------------
+// ssfmtmsg: FormatMessage equivalents. Needed because I added a CString facade
+// Again -- no equivalent of these on non-Win32 builds but their might one day
+// be one if the message facet gets implemented
+// -----------------------------------------------------------------------------
+#if defined (SS_WIN32) && !defined(SS_ANSI)
+ inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
+ DWORD dwLangId, PSTR pBuf, DWORD nSize,
+ va_list* vlArgs)
+ {
+ return FormatMessageA(dwFlags, pSrc, dwMsgId, dwLangId,
+ pBuf, nSize,vlArgs);
+ }
+ inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
+ DWORD dwLangId, PWSTR pBuf, DWORD nSize,
+ va_list* vlArgs)
+ {
+ return FormatMessageW(dwFlags, pSrc, dwMsgId, dwLangId,
+ pBuf, nSize,vlArgs);
+ }
+#else
+#endif
+
+
+
+// FUNCTION: sscpy. Copies up to 'nMax' characters from pSrc to pDst.
+// -----------------------------------------------------------------------------
+// FUNCTION: sscpy
+// inline int sscpy(PSTR pDst, PCSTR pSrc, int nMax=-1);
+// inline int sscpy(PUSTR pDst, PCSTR pSrc, int nMax=-1)
+// inline int sscpy(PSTR pDst, PCWSTR pSrc, int nMax=-1);
+// inline int sscpy(PWSTR pDst, PCWSTR pSrc, int nMax=-1);
+// inline int sscpy(PWSTR pDst, PCSTR pSrc, int nMax=-1);
+//
+// DESCRIPTION:
+// This function is very much (but not exactly) like strcpy. These
+// overloads simplify copying one C-style string into another by allowing
+// the caller to specify two different types of strings if necessary.
+//
+// The strings must NOT overlap
+//
+// "Character" is expressed in terms of the destination string, not
+// the source. If no 'nMax' argument is supplied, then the number of
+// characters copied will be sslen(pSrc). A NULL terminator will
+// also be added so pDst must actually be big enough to hold nMax+1
+// characters. The return value is the number of characters copied,
+// not including the NULL terminator.
+//
+// PARAMETERS:
+// pSrc - the string to be copied FROM. May be a char based string, an
+// MBCS string (in Win32 builds) or a wide string (wchar_t).
+// pSrc - the string to be copied TO. Also may be either MBCS or wide
+// nMax - the maximum number of characters to be copied into szDest. Note
+// that this is expressed in whatever a "character" means to pDst.
+// If pDst is a wchar_t type string than this will be the maximum
+// number of wchar_ts that my be copied. The pDst string must be
+// large enough to hold least nMaxChars+1 characters.
+// If the caller supplies no argument for nMax this is a signal to
+// the routine to copy all the characters in pSrc, regardless of
+// how long it is.
+//
+// RETURN VALUE: none
+// -----------------------------------------------------------------------------
+template<typename CT1, typename CT2>
+inline int sscpycvt(CT1* pDst, const CT2* pSrc, int nChars)
+{
+ StdCodeCvt(pDst, pSrc, nChars);
+ pDst[SSMAX(nChars, 0)] = '\0';
+ return nChars;
+}
+
+template<typename CT1, typename CT2>
+inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax, int nLen)
+{
+ return sscpycvt(pDst, pSrc, SSMIN(nMax, nLen));
+}
+template<typename CT1, typename CT2>
+inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax)
+{
+ return sscpycvt(pDst, pSrc, SSMIN(nMax, sslen(pSrc)));
+}
+template<typename CT1, typename CT2>
+inline int sscpy(CT1* pDst, const CT2* pSrc)
+{
+ return sscpycvt(pDst, pSrc, sslen(pSrc));
+}
+template<typename CT1, typename CT2>
+inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc, int nMax)
+{
+ return sscpycvt(pDst, sSrc.c_str(), SSMIN(nMax, (int)sSrc.length()));
+}
+template<typename CT1, typename CT2>
+inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc)
+{
+ return sscpycvt(pDst, sSrc.c_str(), (int)sSrc.length());
+}
+
+#ifdef SS_INC_COMDEF
+ template<typename CT1>
+ inline int sscpy(CT1* pDst, const _bstr_t& bs, int nMax)
+ {
+ return sscpycvt(pDst, static_cast<PCOLESTR>(bs),
+ SSMIN(nMax, static_cast<int>(bs.length())));
+ }
+ template<typename CT1>
+ inline int sscpy(CT1* pDst, const _bstr_t& bs)
+ {
+ return sscpy(pDst, bs, static_cast<int>(bs.length()));
+ }
+#endif
+
+
+// -----------------------------------------------------------------------------
+// Functional objects for changing case. They also let you pass locales
+// -----------------------------------------------------------------------------
+
+#ifdef SS_ANSI
+ template<typename CT>
+ struct SSToUpper : public std::binary_function<CT, std::locale, CT>
+ {
+ inline CT operator()(const CT& t, const std::locale& loc) const
+ {
+ return sstoupper<CT>(t, loc);
+ }
+ };
+ template<typename CT>
+ struct SSToLower : public std::binary_function<CT, std::locale, CT>
+ {
+ inline CT operator()(const CT& t, const std::locale& loc) const
+ {
+ return sstolower<CT>(t, loc);
+ }
+ };
+#endif
+
+// This struct is used for TrimRight() and TrimLeft() function implementations.
+//template<typename CT>
+//struct NotSpace : public std::unary_function<CT, bool>
+//{
+// const std::locale& loc;
+// inline NotSpace(const std::locale& locArg) : loc(locArg) {}
+// inline bool operator() (CT t) { return !std::isspace(t, loc); }
+//};
+template<typename CT>
+struct NotSpace : public std::unary_function<CT, bool>
+{
+
+ // DINKUMWARE BUG:
+ // Note -- using std::isspace in a COM DLL gives us access violations
+ // because it causes the dynamic addition of a function to be called
+ // when the library shuts down. Unfortunately the list is maintained
+ // in DLL memory but the function is in static memory. So the COM DLL
+ // goes away along with the function that was supposed to be called,
+ // and then later when the DLL CRT shuts down it unloads the list and
+ // tries to call the long-gone function.
+ // This is DinkumWare's implementation problem. Until then, we will
+ // use good old isspace and iswspace from the CRT unless they
+ // specify SS_ANSI
+
+ const std::locale loc;
+ NotSpace(const std::locale& locArg=std::locale()) : loc(locArg) {}
+ bool operator() (CT t) const { return !std::isspace(t, loc); }
+};
+
+
+
+
+// Now we can define the template (finally!)
+// =============================================================================
+// TEMPLATE: CStdStr
+// template<typename CT> class CStdStr : public std::basic_string<CT>
+//
+// REMARKS:
+// This template derives from basic_string<CT> and adds some MFC CString-
+// like functionality
+//
+// Basically, this is my attempt to make Standard C++ library strings as
+// easy to use as the MFC CString class.
+//
+// Note that although this is a template, it makes the assumption that the
+// template argument (CT, the character type) is either char or wchar_t.
+// =============================================================================
+
+//#define CStdStr _SS // avoid compiler warning 4786
+
+// template<typename ARG> ARG& FmtArg(ARG& arg) { return arg; }
+// PCSTR FmtArg(const std::string& arg) { return arg.c_str(); }
+// PCWSTR FmtArg(const std::wstring& arg) { return arg.c_str(); }
+
+template<typename ARG>
+struct FmtArg
+{
+ explicit FmtArg(const ARG& arg) : a_(arg) {}
+ const ARG& Val() const { return a_; }
+ const ARG& a_;
+private:
+ FmtArg& operator=(const FmtArg&) { return *this; }
+};
+
+template<typename CT>
+class CStdStr : public std::basic_string<CT>
+{
+ // Typedefs for shorter names. Using these names also appears to help
+ // us avoid some ambiguities that otherwise arise on some platforms
+
+ typedef typename std::basic_string<CT> MYBASE; // my base class
+ typedef CStdStr<CT> MYTYPE; // myself
+ typedef typename MYBASE::const_pointer PCMYSTR; // PCSTR or PCWSTR
+ typedef typename MYBASE::pointer PMYSTR; // PSTR or PWSTR
+ typedef typename MYBASE::iterator MYITER; // my iterator type
+ typedef typename MYBASE::const_iterator MYCITER; // you get the idea...
+ typedef typename MYBASE::reverse_iterator MYRITER;
+ typedef typename MYBASE::size_type MYSIZE;
+ typedef typename MYBASE::value_type MYVAL;
+ typedef typename MYBASE::allocator_type MYALLOC;
+
+public:
+
+ // shorthand conversion from PCTSTR to string resource ID
+ #define _TRES(pctstr) (LOWORD((DWORD)(pctstr)))
+
+ // CStdStr inline constructors
+ CStdStr()
+ {
+ }
+
+ CStdStr(const MYTYPE& str) : MYBASE(SSREF(str))
+ {
+ }
+
+ CStdStr(const std::string& str)
+ {
+ ssasn(*this, SSREF(str));
+ }
+
+ CStdStr(const std::wstring& str)
+ {
+ ssasn(*this, SSREF(str));
+ }
+
+ CStdStr(PCMYSTR pT, MYSIZE n) : MYBASE(pT, n)
+ {
+ }
+
+#ifdef SS_UNSIGNED
+ CStdStr(PCUSTR pU)
+ {
+ *this = reinterpret_cast<PCSTR>(pU);
+ }
+#endif
+
+ CStdStr(PCSTR pA)
+ {
+ #ifdef SS_ANSI
+ *this = pA;
+ #else
+ if ( 0 != HIWORD(pA) )
+ *this = pA;
+ else if ( 0 != pA && !Load(_TRES(pA)) )
+ TRACE(_T("Can't load string %u\n"), _TRES(pA));
+ #endif
+ }
+
+ CStdStr(PCWSTR pW)
+ {
+ #ifdef SS_ANSI
+ *this = pW;
+ #else
+ if ( 0 != HIWORD(pW) )
+ *this = pW;
+ else if ( 0 != pW && !Load(_TRES(pW)) )
+ TRACE(_T("Can't load string %u\n"), _TRES(pW));
+ #endif
+ }
+
+ CStdStr(MYCITER first, MYCITER last)
+ : MYBASE(first, last)
+ {
+ }
+
+ CStdStr(MYSIZE nSize, MYVAL ch, const MYALLOC& al=MYALLOC())
+ : MYBASE(nSize, ch, al)
+ {
+ }
+
+ #ifdef SS_INC_COMDEF
+ CStdStr(const _bstr_t& bstr)
+ {
+ if ( bstr.length() > 0 )
+ this->append(static_cast<PCMYSTR>(bstr), bstr.length());
+ }
+ #endif
+
+ // CStdStr inline assignment operators -- the ssasn function now takes care
+ // of fixing the MSVC assignment bug (see knowledge base article Q172398).
+ MYTYPE& operator=(const MYTYPE& str)
+ {
+ ssasn(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator=(const std::string& str)
+ {
+ ssasn(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator=(const std::wstring& str)
+ {
+ ssasn(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator=(PCSTR pA)
+ {
+ ssasn(*this, pA);
+ return *this;
+ }
+
+ MYTYPE& operator=(PCWSTR pW)
+ {
+ ssasn(*this, pW);
+ return *this;
+ }
+
+#ifdef SS_UNSIGNED
+ MYTYPE& operator=(PCUSTR pU)
+ {
+ ssasn(*this, reinterpret_cast<PCSTR>(pU)):
+ return *this;
+ }
+#endif
+
+ MYTYPE& operator=(CT t)
+ {
+ Q172398(*this);
+ this->assign(1, t);
+ return *this;
+ }
+
+ #ifdef SS_INC_COMDEF
+ MYTYPE& operator=(const _bstr_t& bstr)
+ {
+ if ( bstr.length() > 0 )
+ {
+ this->assign(static_cast<PCMYSTR>(bstr), bstr.length());
+ return *this;
+ }
+ else
+ {
+ this->erase();
+ return *this;
+ }
+ }
+ #endif
+
+
+ // Overloads also needed to fix the MSVC assignment bug (KB: Q172398)
+ // *** Thanks to Pete The Plumber for catching this one ***
+ // They also are compiled if you have explicitly turned off refcounting
+ #if ( defined(_MSC_VER) && ( _MSC_VER < 1200 ) ) || defined(SS_NO_REFCOUNT)
+
+ MYTYPE& assign(const MYTYPE& str)
+ {
+ ssasn(*this, str);
+ return *this;
+ }
+
+ MYTYPE& assign(const MYTYPE& str, MYSIZE nStart, MYSIZE nChars)
+ {
+ // This overload of basic_string::assign is supposed to assign up to
+ // <nChars> or the NULL terminator, whichever comes first. Since we
+ // are about to call a less forgiving overload (in which <nChars>
+ // must be a valid length), we must adjust the length here to a safe
+ // value. Thanks to Ullrich Pollähne for catching this bug
+
+ nChars = SSMIN(nChars, str.length() - nStart);
+
+ // Watch out for assignment to self
+
+ if ( this == &str )
+ {
+ MYTYPE strTemp(str.c_str()+nStart, nChars);
+ MYBASE::assign(strTemp);
+ }
+ else
+ {
+ Q172398(*this);
+ MYBASE::assign(str.c_str()+nStart, nChars);
+ }
+ return *this;
+ }
+
+ MYTYPE& assign(const MYBASE& str)
+ {
+ ssasn(*this, str);
+ return *this;
+ }
+
+ MYTYPE& assign(const MYBASE& str, MYSIZE nStart, MYSIZE nChars)
+ {
+ // This overload of basic_string::assign is supposed to assign up to
+ // <nChars> or the NULL terminator, whichever comes first. Since we
+ // are about to call a less forgiving overload (in which <nChars>
+ // must be a valid length), we must adjust the length here to a safe
+ // value. Thanks to Ullrich Pollähne for catching this bug
+
+ nChars = SSMIN(nChars, str.length() - nStart);
+
+ // Watch out for assignment to self
+
+ if ( this == &str ) // watch out for assignment to self
+ {
+ MYTYPE strTemp(str.c_str() + nStart, nChars);
+ MYBASE::assign(strTemp);
+ }
+ else
+ {
+ Q172398(*this);
+ MYBASE::assign(str.c_str()+nStart, nChars);
+ }
+ return *this;
+ }
+
+ MYTYPE& assign(const CT* pC, MYSIZE nChars)
+ {
+ // Q172398 only fix -- erase before assigning, but not if we're
+ // assigning from our own buffer
+
+ #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )
+ if ( !this->empty() &&
+ ( pC < this->data() || pC > this->data() + this->capacity() ) )
+ {
+ this->erase();
+ }
+ #endif
+ Q172398(*this);
+ MYBASE::assign(pC, nChars);
+ return *this;
+ }
+
+ MYTYPE& assign(MYSIZE nChars, MYVAL val)
+ {
+ Q172398(*this);
+ MYBASE::assign(nChars, val);
+ return *this;
+ }
+
+ MYTYPE& assign(const CT* pT)
+ {
+ return this->assign(pT, MYBASE::traits_type::length(pT));
+ }
+
+ MYTYPE& assign(MYCITER iterFirst, MYCITER iterLast)
+ {
+ #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )
+ // Q172398 fix. don't call erase() if we're assigning from ourself
+ if ( iterFirst < this->begin() ||
+ iterFirst > this->begin() + this->size() )
+ {
+ this->erase()
+ }
+ #endif
+ this->replace(this->begin(), this->end(), iterFirst, iterLast);
+ return *this;
+ }
+ #endif
+
+
+ // -------------------------------------------------------------------------
+ // CStdStr inline concatenation.
+ // -------------------------------------------------------------------------
+ MYTYPE& operator+=(const MYTYPE& str)
+ {
+ ssadd(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator+=(const std::string& str)
+ {
+ ssadd(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator+=(const std::wstring& str)
+ {
+ ssadd(*this, str);
+ return *this;
+ }
+
+ MYTYPE& operator+=(PCSTR pA)
+ {
+ ssadd(*this, pA);
+ return *this;
+ }
+
+ MYTYPE& operator+=(PCWSTR pW)
+ {
+ ssadd(*this, pW);
+ return *this;
+ }
+
+ MYTYPE& operator+=(CT t)
+ {
+ this->append(1, t);
+ return *this;
+ }
+ #ifdef SS_INC_COMDEF // if we have _bstr_t, define a += for it too.
+ MYTYPE& operator+=(const _bstr_t& bstr)
+ {
+ return this->operator+=(static_cast<PCMYSTR>(bstr));
+ }
+ #endif
+
+
+ // -------------------------------------------------------------------------
+ // Case changing functions
+ // -------------------------------------------------------------------------
+
+ MYTYPE& ToUpper()
+ {
+ // Strictly speaking, this would be about the most portable way
+
+ // std::transform(begin(),
+ // end(),
+ // begin(),
+ // std::bind2nd(SSToUpper<CT>(), std::locale()));
+
+ // But practically speaking, this works faster
+
+ if ( !empty() )
+ ssupr(GetBuf(), this->size());
+
+ return *this;
+ }
+
+
+
+ MYTYPE& ToLower()
+ {
+ // Strictly speaking, this would be about the most portable way
+
+ // std::transform(begin(),
+ // end(),
+ // begin(),
+ // std::bind2nd(SSToLower<CT>(), std::locale()));
+
+ // But practically speaking, this works faster
+
+ if ( !empty() )
+ sslwr(GetBuf(), this->size());
+
+ return *this;
+ }
+
+
+
+ MYTYPE& Normalize()
+ {
+ return Trim().ToLower();
+ }
+
+
+ // -------------------------------------------------------------------------
+ // CStdStr -- Direct access to character buffer. In the MS' implementation,
+ // the at() function that we use here also calls _Freeze() providing us some
+ // protection from multithreading problems associated with ref-counting.
+ // In VC 7 and later, of course, the ref-counting stuff is gone.
+ // -------------------------------------------------------------------------
+
+ CT* GetBuf(int nMinLen=-1)
+ {
+ if ( static_cast<int>(size()) < nMinLen )
+ this->resize(static_cast<MYSIZE>(nMinLen));
+
+ return this->empty() ? const_cast<CT*>(this->data()) : &(this->at(0));
+ }
+
+ CT* SetBuf(int nLen)
+ {
+ nLen = ( nLen > 0 ? nLen : 0 );
+ if ( this->capacity() < 1 && nLen == 0 )
+ this->resize(1);
+
+ this->resize(static_cast<MYSIZE>(nLen));
+ return const_cast<CT*>(this->data());
+ }
+ void RelBuf(int nNewLen=-1)
+ {
+ this->resize(static_cast<MYSIZE>(nNewLen > -1 ? nNewLen :
+ sslen(this->c_str())));
+ }
+
+ void BufferRel() { RelBuf(); } // backwards compatability
+ CT* Buffer() { return GetBuf(); } // backwards compatability
+ CT* BufferSet(int nLen) { return SetBuf(nLen);}// backwards compatability
+
+ bool Equals(const CT* pT, bool bUseCase=false) const
+ { // get copy, THEN compare (thread safe)
+ return bUseCase ? this->compare(pT) == 0 :
+ ssicmp(MYTYPE(*this).c_str(), pT) == 0;
+ }
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: CStdStr::Load
+ // REMARKS:
+ // Loads string from resource specified by nID
+ //
+ // PARAMETERS:
+ // nID - resource Identifier. Purely a Win32 thing in this case
+ //
+ // RETURN VALUE:
+ // true if successful, false otherwise
+ // -------------------------------------------------------------------------
+
+#ifndef SS_ANSI
+
+ bool Load(UINT nId, HMODULE hModule=NULL)
+ {
+ bool bLoaded = false; // set to true of we succeed.
+
+ #ifdef _MFC_VER // When in Rome (or MFC land)...
+
+ CString strRes;
+ bLoaded = FALSE != strRes.LoadString(nId);
+ if ( bLoaded )
+ *this = strRes;
+
+ #else // otherwise make our own hackneyed version of CString's Load
+
+ // Get the resource name and module handle
+
+ if ( NULL == hModule )
+ hModule = GetResourceHandle();
+
+ PCTSTR szName = MAKEINTRESOURCE((nId>>4)+1); // lifted
+ DWORD dwSize = 0;
+
+ // No sense continuing if we can't find the resource
+
+ HRSRC hrsrc = ::FindResource(hModule, szName, RT_STRING);
+
+ if ( NULL == hrsrc )
+ {
+ TRACE(_T("Cannot find resource %d: 0x%X"), nId, ::GetLastError());
+ }
+ else if ( 0 == (dwSize = ::SizeofResource(hModule, hrsrc) / sizeof(CT)))
+ {
+ TRACE(_T("Cant get size of resource %d 0x%X\n"),nId,GetLastError());
+ }
+ else
+ {
+ bLoaded = 0 != ssload(hModule, nId, GetBuf(dwSize), dwSize);
+ ReleaseBuffer();
+ }
+
+ #endif // #ifdef _MFC_VER
+
+ if ( !bLoaded )
+ TRACE(_T("String not loaded 0x%X\n"), ::GetLastError());
+
+ return bLoaded;
+ }
+
+#endif // #ifdef SS_ANSI
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: CStdStr::Format
+ // void _cdecl Formst(CStdStringA& PCSTR szFormat, ...)
+ // void _cdecl Format(PCSTR szFormat);
+ //
+ // DESCRIPTION:
+ // This function does sprintf/wsprintf style formatting on CStdStringA
+ // objects. It looks a lot like MFC's CString::Format. Some people
+ // might even call this identical. Fortunately, these people are now
+ // dead... heh heh.
+ //
+ // PARAMETERS:
+ // nId - ID of string resource holding the format string
+ // szFormat - a PCSTR holding the format specifiers
+ // argList - a va_list holding the arguments for the format specifiers.
+ //
+ // RETURN VALUE: None.
+ // -------------------------------------------------------------------------
+ // formatting (using wsprintf style formatting)
+
+ // If they want a Format() function that safely handles string objects
+ // without casting
+
+#ifdef SS_SAFE_FORMAT
+
+ // Question: Joe, you wacky coder you, why do you have so many overloads
+ // of the Format() function
+ // Answer: One reason only - CString compatability. In short, by making
+ // the Format() function a template this way, I can do strong typing
+ // and allow people to pass CStdString arguments as fillers for
+ // "%s" format specifiers without crashing their program! The downside
+ // is that I need to overload on the number of arguments. If you are
+ // passing more arguments than I have listed below in any of my
+ // overloads, just add another one.
+ //
+ // Yes, yes, this is really ugly. In essence what I am doing here is
+ // protecting people from a bad (and incorrect) programming practice
+ // that they should not be doing anyway. I am protecting them from
+ // themselves. Why am I doing this? Well, if you had any idea the
+ // number of times I've been emailed by people about this
+ // "incompatability" in my code, you wouldn't ask.
+
+ void Fmt(const CT* szFmt, ...)
+ {
+ va_list argList;
+ va_start(argList, szFmt);
+ FormatV(szFmt, argList);
+ va_end(argList);
+ }
+
+#ifndef SS_ANSI
+
+ void Format(UINT nId)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ this->swap(strFmt);
+ }
+ template<class A1>
+ void Format(UINT nId, const A1& v)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ Fmt(strFmt, FmtArg<A1>(v).Val());
+ }
+ template<class A1, class A2>
+ void Format(UINT nId, const A1& v1, const A2& v2)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val());
+ }
+ template<class A1, class A2, class A3>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(),FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(),FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(),FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15, class A16>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15,
+ const A16& v16)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val(), FmtArg<A16>(v16).Val());
+ }
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15, class A16, class A17>
+ void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15,
+ const A16& v16, const A17& v17)
+ {
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ {
+ Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val(),FmtArg<A16>(v16).Val(),FmtArg<A17>(v17).Val());
+ }
+ }
+
+#endif // #ifndef SS_ANSI
+
+ // ...now the other overload of Format: the one that takes a string literal
+
+ void Format(const CT* szFmt)
+ {
+ *this = szFmt;
+ }
+ template<class A1>
+ void Format(const CT* szFmt, A1 v)
+ {
+ Fmt(szFmt, FmtArg<A1>(v).Val());
+ }
+ template<class A1, class A2>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val());
+ }
+ template<class A1, class A2, class A3>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val());
+ }
+ template<class A1, class A2, class A3, class A4>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(),FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15, class A16>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15,
+ const A16& v16)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val(), FmtArg<A16>(v16).Val());
+ }
+ template<class A1, class A2, class A3, class A4, class A5, class A6,
+ class A7, class A8, class A9, class A10, class A11, class A12,
+ class A13, class A14, class A15, class A16, class A17>
+ void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,
+ const A4& v4, const A5& v5, const A6& v6, const A7& v7,
+ const A8& v8, const A9& v9, const A10& v10, const A11& v11,
+ const A12& v12, const A13& v13, const A14& v14, const A15& v15,
+ const A16& v16, const A17& v17)
+ {
+ Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),
+ FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),
+ FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),
+ FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),
+ FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),
+ FmtArg<A15>(v15).Val(),FmtArg<A16>(v16).Val(),FmtArg<A17>(v17).Val());
+ }
+
+#else // #ifdef SS_SAFE_FORMAT
+
+
+#ifndef SS_ANSI
+
+ void Format(UINT nId, ...)
+ {
+ va_list argList;
+ va_start(argList, nId);
+ va_start(argList, nId);
+
+ MYTYPE strFmt;
+ if ( strFmt.Load(nId) )
+ FormatV(strFmt, argList);
+
+ va_end(argList);
+ }
+
+#endif // #ifdef SS_ANSI
+
+ void Format(const CT* szFmt, ...)
+ {
+ va_list argList;
+ va_start(argList, szFmt);
+ FormatV(szFmt, argList);
+ va_end(argList);
+ }
+
+#endif // #ifdef SS_SAFE_FORMAT
+
+ void AppendFormat(const CT* szFmt, ...)
+ {
+ va_list argList;
+ va_start(argList, szFmt);
+ AppendFormatV(szFmt, argList);
+ va_end(argList);
+ }
+
+ #define MAX_FMT_TRIES 5 // #of times we try
+ #define FMT_BLOCK_SIZE 2048 // # of bytes to increment per try
+ #define BUFSIZE_1ST 256
+ #define BUFSIZE_2ND 512
+ #define STD_BUF_SIZE 1024
+
+ // an efficient way to add formatted characters to the string. You may only
+ // add up to STD_BUF_SIZE characters at a time, though
+ void AppendFormatV(const CT* szFmt, va_list argList)
+ {
+ CT szBuf[STD_BUF_SIZE];
+ #ifdef SS_ANSI
+ int nLen = ssvsprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);
+ #else
+ int nLen = ssnprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);
+ #endif
+ if ( 0 < nLen )
+ this->append(szBuf, nLen);
+ }
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: FormatV
+ // void FormatV(PCSTR szFormat, va_list, argList);
+ //
+ // DESCRIPTION:
+ // This function formats the string with sprintf style format-specs.
+ // It makes a general guess at required buffer size and then tries
+ // successively larger buffers until it finds one big enough or a
+ // threshold (MAX_FMT_TRIES) is exceeded.
+ //
+ // PARAMETERS:
+ // szFormat - a PCSTR holding the format of the output
+ // argList - a Microsoft specific va_list for variable argument lists
+ //
+ // RETURN VALUE:
+ // -------------------------------------------------------------------------
+
+ void FormatV(const CT* szFormat, va_list argList)
+ {
+ #ifdef SS_ANSI
+
+ int nLen = sslen(szFormat) + STD_BUF_SIZE;
+ ssvsprintf(GetBuffer(nLen), nLen-1, szFormat, argList);
+ ReleaseBuffer();
+
+ #else
+
+ CT* pBuf = NULL;
+ int nChars = 1;
+ int nUsed = 0;
+ size_type nActual = 0;
+ int nTry = 0;
+
+ do
+ {
+ // Grow more than linearly (e.g. 512, 1536, 3072, etc)
+
+ nChars += ((nTry+1) * FMT_BLOCK_SIZE);
+ pBuf = reinterpret_cast<CT*>(_alloca(sizeof(CT)*nChars));
+ nUsed = ssnprintf(pBuf, nChars-1, szFormat, argList);
+
+ // Ensure proper NULL termination.
+
+ nActual = nUsed == -1 ? nChars-1 : SSMIN(nUsed, nChars-1);
+ pBuf[nActual+1]= '\0';
+
+
+ } while ( nUsed < 0 && nTry++ < MAX_FMT_TRIES );
+
+ // assign whatever we managed to format
+
+ this->assign(pBuf, nActual);
+
+ #endif
+ }
+
+
+ // -------------------------------------------------------------------------
+ // CString Facade Functions:
+ //
+ // The following methods are intended to allow you to use this class as a
+ // drop-in replacement for CString.
+ // -------------------------------------------------------------------------
+ #ifdef SS_WIN32
+ BSTR AllocSysString() const
+ {
+ ostring os;
+ ssasn(os, *this);
+ return ::SysAllocString(os.c_str());
+ }
+ #endif
+
+ int Collate(PCMYSTR szThat) const
+ {
+ return sscoll(this->c_str(), this->length(), szThat, sslen(szThat));
+ }
+
+ int CollateNoCase(PCMYSTR szThat) const
+ {
+ return ssicoll(this->c_str(), this->length(), szThat, sslen(szThat));
+ }
+
+ int Compare(PCMYSTR szThat) const
+ {
+ return this->compare(szThat);
+ }
+
+ int CompareNoCase(PCMYSTR szThat) const
+ {
+ return ssicmp(this->c_str(), szThat);
+ }
+
+ int Delete(int nIdx, int nCount=1)
+ {
+ if ( nIdx < 0 )
+ nIdx = 0;
+
+ if ( nIdx < GetLength() )
+ this->erase(static_cast<MYSIZE>(nIdx), static_cast<MYSIZE>(nCount));
+
+ return GetLength();
+ }
+
+ void Empty()
+ {
+ this->erase();
+ }
+
+ int Find(CT ch) const
+ {
+ MYSIZE nIdx = this->find_first_of(ch);
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ int Find(PCMYSTR szSub) const
+ {
+ MYSIZE nIdx = this->find(szSub);
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ int Find(CT ch, int nStart) const
+ {
+ // CString::Find docs say add 1 to nStart when it's not zero
+ // CString::Find code doesn't do that however. We'll stick
+ // with what the code does
+
+ MYSIZE nIdx = this->find_first_of(ch, static_cast<MYSIZE>(nStart));
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ int Find(PCMYSTR szSub, int nStart) const
+ {
+ // CString::Find docs say add 1 to nStart when it's not zero
+ // CString::Find code doesn't do that however. We'll stick
+ // with what the code does
+
+ MYSIZE nIdx = this->find(szSub, static_cast<MYSIZE>(nStart));
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ int FindOneOf(PCMYSTR szCharSet) const
+ {
+ MYSIZE nIdx = this->find_first_of(szCharSet);
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+#ifndef SS_ANSI
+ void FormatMessage(PCMYSTR szFormat, ...) throw(std::exception)
+ {
+ va_list argList;
+ va_start(argList, szFormat);
+ PMYSTR szTemp;
+ if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ szFormat, 0, 0,
+ reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||
+ szTemp == 0 )
+ {
+ throw std::runtime_error("out of memory");
+ }
+ *this = szTemp;
+ LocalFree(szTemp);
+ va_end(argList);
+ }
+
+ void FormatMessage(UINT nFormatId, ...) throw(std::exception)
+ {
+ MYTYPE sFormat;
+ VERIFY(sFormat.LoadString(nFormatId) != 0);
+ va_list argList;
+ va_start(argList, nFormatId);
+ PMYSTR szTemp;
+ if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ sFormat, 0, 0,
+ reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||
+ szTemp == 0)
+ {
+ throw std::runtime_error("out of memory");
+ }
+ *this = szTemp;
+ LocalFree(szTemp);
+ va_end(argList);
+ }
+#endif
+
+
+ // -------------------------------------------------------------------------
+ // GetXXXX -- Direct access to character buffer
+ // -------------------------------------------------------------------------
+ CT GetAt(int nIdx) const
+ {
+ return this->at(static_cast<MYSIZE>(nIdx));
+ }
+
+ CT* GetBuffer(int nMinLen=-1)
+ {
+ return GetBuf(nMinLen);
+ }
+
+ CT* GetBufferSetLength(int nLen)
+ {
+ return BufferSet(nLen);
+ }
+
+ // GetLength() -- MFC docs say this is the # of BYTES but
+ // in truth it is the number of CHARACTERs (chars or wchar_ts)
+ int GetLength() const
+ {
+ return static_cast<int>(this->length());
+ }
+
+
+ int Insert(int nIdx, CT ch)
+ {
+ if ( static_cast<MYSIZE>(nIdx) > this->size() -1 )
+ this->append(1, ch);
+ else
+ this->insert(static_cast<MYSIZE>(nIdx), 1, ch);
+
+ return GetLength();
+ }
+ int Insert(int nIdx, PCMYSTR sz)
+ {
+ if ( nIdx >= this->size() )
+ this->append(sz, sslen(sz));
+ else
+ this->insert(static_cast<MYSIZE>(nIdx), sz);
+
+ return GetLength();
+ }
+
+ bool IsEmpty() const
+ {
+ return this->empty();
+ }
+
+ MYTYPE Left(int nCount) const
+ {
+ // Range check the count.
+
+ nCount = SSMAX(0, SSMIN(nCount, static_cast<int>(this->size())));
+ return this->substr(0, static_cast<MYSIZE>(nCount));
+ }
+
+#ifndef SS_ANSI
+ bool LoadString(UINT nId)
+ {
+ return this->Load(nId);
+ }
+#endif
+
+ void MakeLower()
+ {
+ ToLower();
+ }
+
+ void MakeReverse()
+ {
+ std::reverse(this->begin(), this->end());
+ }
+
+ void MakeUpper()
+ {
+ ToUpper();
+ }
+
+ MYTYPE Mid(int nFirst ) const
+ {
+ return Mid(nFirst, size()-nFirst);
+ }
+
+ MYTYPE Mid(int nFirst, int nCount) const
+ {
+ // CString does range checking here. Since we're trying to emulate it,
+ // we must check too.
+
+ if ( nFirst < 0 )
+ nFirst = 0;
+ if ( nCount < 0 )
+ nCount = 0;
+
+ if ( nFirst + nCount > size() )
+ nCount = size() - nFirst;
+
+ if ( nFirst > size() )
+ return MYTYPE();
+
+ ASSERT(nFirst >= 0);
+ ASSERT(nFirst + nCount <= size());
+
+ return this->substr(static_cast<MYSIZE>(nFirst),
+ static_cast<MYSIZE>(nCount));
+ }
+
+ void ReleaseBuffer(int nNewLen=-1)
+ {
+ RelBuf(nNewLen);
+ }
+
+ int Remove(CT ch)
+ {
+ MYSIZE nIdx = 0;
+ int nRemoved = 0;
+ while ( (nIdx=this->find_first_of(ch)) != MYBASE::npos )
+ {
+ this->erase(nIdx, 1);
+ nRemoved++;
+ }
+ return nRemoved;
+ }
+
+ int Replace(CT chOld, CT chNew)
+ {
+ int nReplaced = 0;
+ for ( MYITER iter=this->begin(); iter != this->end(); iter++ )
+ {
+ if ( *iter == chOld )
+ {
+ *iter = chNew;
+ nReplaced++;
+ }
+ }
+ return nReplaced;
+ }
+
+ int Replace(PCMYSTR szOld, PCMYSTR szNew)
+ {
+ int nReplaced = 0;
+ MYSIZE nIdx = 0;
+ MYSIZE nOldLen = sslen(szOld);
+ if ( 0 == nOldLen )
+ return 0;
+
+ static const CT ch = CT(0);
+ MYSIZE nNewLen = sslen(szNew);
+ PCMYSTR szRealNew = szNew == 0 ? &ch : szNew;
+
+ while ( (nIdx=this->find(szOld, nIdx)) != MYBASE::npos )
+ {
+ replace(this->begin()+nIdx, this->begin()+nIdx+nOldLen, szRealNew);
+ nReplaced++;
+ nIdx += nNewLen;
+ }
+ return nReplaced;
+ }
+
+ int ReverseFind(CT ch) const
+ {
+ MYSIZE nIdx = this->find_last_of(ch);
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ // ReverseFind overload that's not in CString but might be useful
+ int ReverseFind(PCMYSTR szFind, MYSIZE pos=MYBASE::npos) const
+ {
+ MYSIZE nIdx = this->rfind(0 == szFind ? MYTYPE() : szFind, pos);
+ return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);
+ }
+
+ MYTYPE Right(int nCount) const
+ {
+ // Range check the count.
+
+ nCount = SSMAX(0, SSMIN(nCount, static_cast<int>(this->size())));
+ return this->substr(this->size()-static_cast<MYSIZE>(nCount));
+ }
+
+ void SetAt(int nIndex, CT ch)
+ {
+ ASSERT(this->size() > static_cast<MYSIZE>(nIndex));
+ this->at(static_cast<MYSIZE>(nIndex)) = ch;
+ }
+
+#ifndef SS_ANSI
+ BSTR SetSysString(BSTR* pbstr) const
+ {
+ ostring os;
+ ssasn(os, *this);
+ if ( !::SysReAllocStringLen(pbstr, os.c_str(), os.length()) )
+ throw std::runtime_error("out of memory");
+
+ ASSERT(*pbstr != 0);
+ return *pbstr;
+ }
+#endif
+
+ MYTYPE SpanExcluding(PCMYSTR szCharSet) const
+ {
+ MYSIZE pos = this->find_first_of(szCharSet);
+ return pos == MYBASE::npos ? *this : Left(pos);
+ }
+
+ MYTYPE SpanIncluding(PCMYSTR szCharSet) const
+ {
+ MYSIZE pos = this->find_first_not_of(szCharSet);
+ return pos == MYBASE::npos ? *this : Left(pos);
+ }
+
+#if !defined(UNICODE) && !defined(SS_ANSI)
+
+ // CString's OemToAnsi and AnsiToOem functions are available only in
+ // Unicode builds. However since we're a template we also need a
+ // runtime check of CT and a reinterpret_cast to account for the fact
+ // that CStdStringW gets instantiated even in non-Unicode builds.
+
+ void AnsiToOem()
+ {
+ if ( sizeof(CT) == sizeof(char) && !empty() )
+ {
+ ::CharToOem(reinterpret_cast<PCSTR>(this->c_str()),
+ reinterpret_cast<PSTR>(GetBuf()));
+ }
+ else
+ {
+ ASSERT(false);
+ }
+ }
+
+ void OemToAnsi()
+ {
+ if ( sizeof(CT) == sizeof(char) && !empty() )
+ {
+ ::OemToChar(reinterpret_cast<PCSTR>(this->c_str()),
+ reinterpret_cast<PSTR>(GetBuf()));
+ }
+ else
+ {
+ ASSERT(false);
+ }
+ }
+
+#endif
+
+
+ // -------------------------------------------------------------------------
+ // Trim and its variants
+ // -------------------------------------------------------------------------
+ MYTYPE& Trim()
+ {
+ return TrimLeft().TrimRight();
+ }
+
+ MYTYPE& TrimLeft()
+ {
+ this->erase(this->begin(),
+ std::find_if(this->begin(), this->end(), NotSpace<CT>()));
+
+ return *this;
+ }
+
+ MYTYPE& TrimLeft(CT tTrim)
+ {
+ this->erase(0, this->find_first_not_of(tTrim));
+ return *this;
+ }
+
+ MYTYPE& TrimLeft(PCMYSTR szTrimChars)
+ {
+ this->erase(0, this->find_first_not_of(szTrimChars));
+ return *this;
+ }
+
+ MYTYPE& TrimRight()
+ {
+ // NOTE: When comparing reverse_iterators here (MYRITER), I avoid using
+ // operator!=. This is because namespace rel_ops also has a template
+ // operator!= which conflicts with the global operator!= already defined
+ // for reverse_iterator in the header <utility>.
+ // Thanks to John James for alerting me to this.
+
+ MYRITER it = std::find_if(this->rbegin(), this->rend(), NotSpace<CT>());
+ if ( !(this->rend() == it) )
+ this->erase(this->rend() - it);
+
+ this->erase(!(it == this->rend()) ? this->find_last_of(*it) + 1 : 0);
+ return *this;
+ }
+
+ MYTYPE& TrimRight(CT tTrim)
+ {
+ MYSIZE nIdx = this->find_last_not_of(tTrim);
+ this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);
+ return *this;
+ }
+
+ MYTYPE& TrimRight(PCMYSTR szTrimChars)
+ {
+ MYSIZE nIdx = this->find_last_not_of(szTrimChars);
+ this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);
+ return *this;
+ }
+
+ void FreeExtra()
+ {
+ MYTYPE mt;
+ this->swap(mt);
+ if ( !mt.empty() )
+ this->assign(mt.c_str(), mt.size());
+ }
+
+ // I have intentionally not implemented the following CString
+ // functions. You cannot make them work without taking advantage
+ // of implementation specific behavior. However if you absolutely
+ // MUST have them, uncomment out these lines for "sort-of-like"
+ // their behavior. You're on your own.
+
+// CT* LockBuffer() { return GetBuf(); }// won't really lock
+// void UnlockBuffer(); { } // why have UnlockBuffer w/o LockBuffer?
+
+ // Array-indexing operators. Required because we defined an implicit cast
+ // to operator const CT* (Thanks to Julian Selman for pointing this out)
+ CT& operator[](int nIdx)
+ {
+ return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
+ }
+
+ const CT& operator[](int nIdx) const
+ {
+ return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
+ }
+
+ CT& operator[](unsigned int nIdx)
+ {
+ return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
+ }
+
+ const CT& operator[](unsigned int nIdx) const
+ {
+ return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
+ }
+
+#ifndef SS_NO_IMPLICIT_CAST
+ operator const CT*() const
+ {
+ return this->c_str();
+ }
+#endif
+
+ // IStream related functions. Useful in IPersistStream implementations
+
+#ifdef SS_INC_COMDEF
+
+ // struct SSSHDR - useful for non Std C++ persistence schemes.
+ typedef struct SSSHDR
+ {
+ BYTE byCtrl;
+ ULONG nChars;
+ } SSSHDR; // as in "Standard String Stream Header"
+
+ #define SSSO_UNICODE 0x01 // the string is a wide string
+ #define SSSO_COMPRESS 0x02 // the string is compressed
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: StreamSize
+ // REMARKS:
+ // Returns how many bytes it will take to StreamSave() this CStdString
+ // object to an IStream.
+ // -------------------------------------------------------------------------
+ ULONG StreamSize() const
+ {
+ // Control header plus string
+ ASSERT(this->size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));
+ return (this->size() * sizeof(CT)) + sizeof(SSSHDR);
+ }
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: StreamSave
+ // REMARKS:
+ // Saves this CStdString object to a COM IStream.
+ // -------------------------------------------------------------------------
+ HRESULT StreamSave(IStream* pStream) const
+ {
+ ASSERT(size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));
+ HRESULT hr = E_FAIL;
+ ASSERT(pStream != 0);
+ SSSHDR hdr;
+ hdr.byCtrl = sizeof(CT) == 2 ? SSSO_UNICODE : 0;
+ hdr.nChars = this->size();
+
+
+ if ( FAILED(hr=pStream->Write(&hdr, sizeof(SSSHDR), 0)) )
+ TRACE(_T("StreamSave: Cannot write control header, ERR=0x%X\n"),hr);
+ else if ( empty() )
+ ; // nothing to write
+ else if ( FAILED(hr=pStream->Write(this->c_str(), this->size()*sizeof(CT), 0)) )
+ TRACE(_T("StreamSave: Cannot write string to stream 0x%X\n"), hr);
+
+ return hr;
+ }
+
+
+ // -------------------------------------------------------------------------
+ // FUNCTION: StreamLoad
+ // REMARKS:
+ // This method loads the object from an IStream.
+ // -------------------------------------------------------------------------
+ HRESULT StreamLoad(IStream* pStream)
+ {
+ ASSERT(pStream != 0);
+ SSSHDR hdr;
+ HRESULT hr = E_FAIL;
+
+ if ( FAILED(hr=pStream->Read(&hdr, sizeof(SSSHDR), 0)) )
+ {
+ TRACE(_T("StreamLoad: Cant read control header, ERR=0x%X\n"), hr);
+ }
+ else if ( hdr.nChars > 0 )
+ {
+ ULONG nRead = 0;
+ PMYSTR pMyBuf = BufferSet(hdr.nChars);
+
+ // If our character size matches the character size of the string
+ // we're trying to read, then we can read it directly into our
+ // buffer. Otherwise, we have to read into an intermediate buffer
+ // and convert.
+
+ if ( (hdr.byCtrl & SSSO_UNICODE) != 0 )
+ {
+ ULONG nBytes = hdr.nChars * sizeof(wchar_t);
+ if ( sizeof(CT) == sizeof(wchar_t) )
+ {
+ if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
+ TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
+ }
+ else
+ {
+ PWSTR pBufW = reinterpret_cast<PWSTR>(_alloca((nBytes)+1));
+ if ( FAILED(hr=pStream->Read(pBufW, nBytes, &nRead)) )
+ TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
+ else
+ sscpy(pMyBuf, pBufW, hdr.nChars);
+ }
+ }
+ else
+ {
+ ULONG nBytes = hdr.nChars * sizeof(char);
+ if ( sizeof(CT) == sizeof(char) )
+ {
+ if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
+ TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
+ }
+ else
+ {
+ PSTR pBufA = reinterpret_cast<PSTR>(_alloca(nBytes));
+ if ( FAILED(hr=pStream->Read(pBufA, hdr.nChars, &nRead)) )
+ TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
+ else
+ sscpy(pMyBuf, pBufA, hdr.nChars);
+ }
+ }
+ }
+ else
+ {
+ this->erase();
+ }
+ return hr;
+ }
+#endif // #ifdef SS_INC_COMDEF
+
+#ifndef SS_ANSI
+
+ // SetResourceHandle/GetResourceHandle. In MFC builds, these map directly
+ // to AfxSetResourceHandle and AfxGetResourceHandle. In non-MFC builds they
+ // point to a single static HINST so that those who call the member
+ // functions that take resource IDs can provide an alternate HINST of a DLL
+ // to search. This is not exactly the list of HMODULES that MFC provides
+ // but it's better than nothing.
+
+#ifdef _MFC_VER
+ static void SetResourceHandle(HMODULE hNew)
+ {
+ AfxSetResourceHandle(hNew);
+ }
+ static HMODULE GetResourceHandle()
+ {
+ return AfxGetResourceHandle();
+ }
+#else
+ static void SetResourceHandle(HMODULE hNew)
+ {
+ SSResourceHandle() = hNew;
+ }
+ static HMODULE GetResourceHandle()
+ {
+ return SSResourceHandle();
+ }
+#endif
+
+
+ template<typename CT2>
+ MYTYPE operator+(const CStdStr<CT2>& s2)
+ {
+ MYTYPE strRet(SSREF(*this));
+ strRet += s2.c_str();
+ return strRet;
+ }
+
+
+#endif
+};
+
+
+
+// -----------------------------------------------------------------------------
+// CStdStr friend addition functions defined as inline
+// -----------------------------------------------------------------------------
+template<typename CT>
+inline
+CStdStr<CT> operator+(const CStdStr<CT>& str1, const CStdStr<CT>& str2)
+{
+ CStdStr<CT> strRet(SSREF(str1));
+ strRet.append(str2);
+ return strRet;
+}
+
+template<typename CT>
+inline
+CStdStr<CT> operator+(const CStdStr<CT>& str, CT t)
+{
+ // this particular overload is needed for disabling reference counting
+ // though it's only an issue from line 1 to line 2
+
+ CStdStr<CT> strRet(SSREF(str)); // 1
+ strRet.append(1, t); // 2
+ return strRet;
+}
+
+template<typename CT>
+inline
+CStdStr<CT> operator+(const CStdStr<CT>& str, PCSTR pA)
+{
+ return CStdStr<CT>(str) + CStdStr<CT>(pA);
+}
+
+template<typename CT>
+inline
+CStdStr<CT> operator+(PCSTR pA, const CStdStr<CT>& str)
+{
+ CStdStr<CT> strRet(pA);
+ strRet.append(str);
+ return strRet;
+}
+
+template<typename CT>
+inline
+CStdStr<CT> operator+(const CStdStr<CT>& str, PCWSTR pW)
+{
+ return CStdStr<CT>(SSREF(str)) + CStdStr<CT>(pW);
+}
+
+template<typename CT>
+inline
+CStdStr<CT> operator+(PCWSTR pW, const CStdStr<CT>& str)
+{
+ CStdStr<CT> strRet(pW);
+ strRet.append(str);
+ return strRet;
+}
+
+#ifdef SS_INC_COMDEF
+ template<typename CT>
+ inline
+ CStdStr<CT> operator+(const _bstr_t& bstr, const CStdStr<CT>& str)
+ {
+ return static_cast<const CT*>(bstr) + str;
+ }
+
+ template<typename CT>
+ inline
+ CStdStr<CT> operator+(const CStdStr<CT>& str, const _bstr_t& bstr)
+ {
+ return str + static_cast<const CT*>(bstr);
+ }
+#endif
+
+// -----------------------------------------------------------------------------
+// HOW TO EXPORT CSTDSTRING FROM A DLL
+//
+// If you want to export CStdStringA and CStdStringW from a DLL, then all you
+// need to
+// 1. make sure that all components link to the same DLL version
+// of the CRT (not the static one).
+// 2. Uncomment the 3 lines of code below
+// 3. #define 2 macros per the instructions in MS KnowledgeBase
+// article Q168958. The macros are:
+//
+// MACRO DEFINTION WHEN EXPORTING DEFINITION WHEN IMPORTING
+// ----- ------------------------ -------------------------
+// SSDLLEXP (nothing, just #define it) extern
+// SSDLLSPEC __declspec(dllexport) __declspec(dllimport)
+//
+// Note that these macros must be available to ALL clients who want to
+// link to the DLL and use the class. If they
+// -----------------------------------------------------------------------------
+//#pragma warning(disable:4231) // non-standard extension ("extern template")
+// SSDLLEXP template class SSDLLSPEC CStdStr<char>;
+// SSDLLEXP template class SSDLLSPEC CStdStr<wchar_t>;
+
+// =============================================================================
+// END OF CStdStr INLINE FUNCTION DEFINITIONS
+// =============================================================================
+
+// Now typedef our class names based upon this humongous template
+
+typedef CStdStr<char> CStdStringA; // a better std::string
+typedef CStdStr<wchar_t> CStdStringW; // a better std::wstring
+typedef CStdStr<OLECHAR> CStdStringO; // almost always CStdStringW
+
+
+// New-style format function is a template
+
+#ifdef SS_SAFE_FORMAT
+
+template<>
+struct FmtArg<CStdStringA>
+{
+ explicit FmtArg(const CStdStringA& arg) : a_(arg) {}
+ PCSTR Val() const { return a_.c_str(); }
+ const CStdStringA& a_;
+private:
+ FmtArg<CStdStringA>& operator=(const FmtArg<CStdStringA>&) { return *this; }
+};
+template<>
+struct FmtArg<CStdStringW>
+{
+ explicit FmtArg(const CStdStringW& arg) : a_(arg) {}
+ PCWSTR Val() const { return a_.c_str(); }
+ const CStdStringW& a_;
+private:
+ FmtArg<CStdStringW>& operator=(const FmtArg<CStdStringW>&) { return *this; }
+};
+
+template<>
+struct FmtArg<std::string>
+{
+ explicit FmtArg(const std::string& arg) : a_(arg) {}
+ PCSTR Val() const { return a_.c_str(); }
+ const std::string& a_;
+private:
+ FmtArg<std::string>& operator=(const FmtArg<std::string>&) { return *this; }
+};
+template<>
+struct FmtArg<std::wstring>
+{
+ explicit FmtArg(const std::wstring& arg) : a_(arg) {}
+ PCWSTR Val() const { return a_.c_str(); }
+ const std::wstring& a_;
+private:
+ FmtArg<std::wstring>& operator=(const FmtArg<std::wstring>&) {return *this;}
+};
+#endif // #ifdef SS_SAFEFORMAT
+
+#ifndef SS_ANSI
+ // SSResourceHandle: our MFC-like resource handle
+ inline HMODULE& SSResourceHandle()
+ {
+ static HMODULE hModuleSS = GetModuleHandle(0);
+ return hModuleSS;
+ }
+#endif
+
+
+
+
+// In MFC builds, define some global serialization operators
+// Special operators that allow us to serialize CStdStrings to CArchives.
+// Note that we use an intermediate CString object in order to ensure that
+// we use the exact same format.
+
+#ifdef _MFC_VER
+ inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringA& strA)
+ {
+ CString strTemp = strA;
+ return ar << strTemp;
+ }
+ inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringW& strW)
+ {
+ CString strTemp = strW;
+ return ar << strTemp;
+ }
+
+ inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringA& strA)
+ {
+ CString strTemp;
+ ar >> strTemp;
+ strA = strTemp;
+ return ar;
+ }
+ inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringW& strW)
+ {
+ CString strTemp;
+ ar >> strTemp;
+ strW = strTemp;
+ return ar;
+ }
+#endif // #ifdef _MFC_VER -- (i.e. is this MFC?)
+
+
+
+// -----------------------------------------------------------------------------
+// GLOBAL FUNCTION: WUFormat
+// CStdStringA WUFormat(UINT nId, ...);
+// CStdStringA WUFormat(PCSTR szFormat, ...);
+//
+// REMARKS:
+// This function allows the caller for format and return a CStdStringA
+// object with a single line of code.
+// -----------------------------------------------------------------------------
+#ifdef SS_ANSI
+#else
+ inline CStdStringA WUFormatA(UINT nId, ...)
+ {
+ va_list argList;
+ va_start(argList, nId);
+
+ CStdStringA strFmt;
+ CStdStringA strOut;
+ if ( strFmt.Load(nId) )
+ strOut.FormatV(strFmt, argList);
+
+ va_end(argList);
+ return strOut;
+ }
+ inline CStdStringA WUFormatA(PCSTR szFormat, ...)
+ {
+ va_list argList;
+ va_start(argList, szFormat);
+ CStdStringA strOut;
+ strOut.FormatV(szFormat, argList);
+ va_end(argList);
+ return strOut;
+ }
+
+ inline CStdStringW WUFormatW(UINT nId, ...)
+ {
+ va_list argList;
+ va_start(argList, nId);
+
+ CStdStringW strFmt;
+ CStdStringW strOut;
+ if ( strFmt.Load(nId) )
+ strOut.FormatV(strFmt, argList);
+
+ va_end(argList);
+ return strOut;
+ }
+ inline CStdStringW WUFormatW(PCWSTR szwFormat, ...)
+ {
+ va_list argList;
+ va_start(argList, szwFormat);
+ CStdStringW strOut;
+ strOut.FormatV(szwFormat, argList);
+ va_end(argList);
+ return strOut;
+ }
+#endif // #ifdef SS_ANSI
+
+#ifdef SS_WIN32
+ // -------------------------------------------------------------------------
+ // FUNCTION: WUSysMessage
+ // CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);
+ // CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);
+ //
+ // DESCRIPTION:
+ // This function simplifies the process of obtaining a string equivalent
+ // of a system error code returned from GetLastError(). You simply
+ // supply the value returned by GetLastError() to this function and the
+ // corresponding system string is returned in the form of a CStdStringA.
+ //
+ // PARAMETERS:
+ // dwError - a DWORD value representing the error code to be translated
+ // dwLangId - the language id to use. defaults to english.
+ //
+ // RETURN VALUE:
+ // a CStdStringA equivalent of the error code. Currently, this function
+ // only returns either English of the system default language strings.
+ // -------------------------------------------------------------------------
+ #define SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
+ inline CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
+ {
+ CHAR szBuf[512];
+
+ if ( 0 != ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
+ dwLangId, szBuf, 511, NULL) )
+ return WUFormatA("%s (0x%X)", szBuf, dwError);
+ else
+ return WUFormatA("Unknown error (0x%X)", dwError);
+ }
+ inline CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
+ {
+ WCHAR szBuf[512];
+
+ if ( 0 != ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
+ dwLangId, szBuf, 511, NULL) )
+ return WUFormatW(L"%s (0x%X)", szBuf, dwError);
+ else
+ return WUFormatW(L"Unknown error (0x%X)", dwError);
+ }
+#endif
+
+// Define TCHAR based friendly names for some of these functions
+
+#ifdef UNICODE
+ #define CStdString CStdStringW
+ #define WUSysMessage WUSysMessageW
+ #define WUFormat WUFormatW
+#else
+ #define CStdString CStdStringA
+ #define WUSysMessage WUSysMessageA
+ #define WUFormat WUFormatA
+#endif
+
+// ...and some shorter names for the space-efficient
+
+#define WUSysMsg WUSysMessage
+#define WUSysMsgA WUSysMessageA
+#define WUSysMsgW WUSysMessageW
+#define WUFmtA WUFormatA
+#define WUFmtW WUFormatW
+#define WUFmt WUFormat
+#define WULastErrMsg() WUSysMessage(::GetLastError())
+#define WULastErrMsgA() WUSysMessageA(::GetLastError())
+#define WULastErrMsgW() WUSysMessageW(::GetLastError())
+
+
+// -----------------------------------------------------------------------------
+// FUNCTIONAL COMPARATORS:
+// REMARKS:
+// These structs are derived from the std::binary_function template. They
+// give us functional classes (which may be used in Standard C++ Library
+// collections and algorithms) that perform case-insensitive comparisons of
+// CStdString objects. This is useful for maps in which the key may be the
+// proper string but in the wrong case.
+// -----------------------------------------------------------------------------
+#define StdStringLessNoCaseW SSLNCW // avoid VC compiler warning 4786
+#define StdStringEqualsNoCaseW SSENCW
+#define StdStringLessNoCaseA SSLNCA
+#define StdStringEqualsNoCaseA SSENCA
+
+#ifdef UNICODE
+ #define StdStringLessNoCase SSLNCW
+ #define StdStringEqualsNoCase SSENCW
+#else
+ #define StdStringLessNoCase SSLNCA
+ #define StdStringEqualsNoCase SSENCA
+#endif
+
+struct StdStringLessNoCaseW
+ : std::binary_function<CStdStringW, CStdStringW, bool>
+{
+ inline
+ bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const
+ { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }
+};
+struct StdStringEqualsNoCaseW
+ : std::binary_function<CStdStringW, CStdStringW, bool>
+{
+ inline
+ bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const
+ { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }
+};
+struct StdStringLessNoCaseA
+ : std::binary_function<CStdStringA, CStdStringA, bool>
+{
+ inline
+ bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const
+ { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }
+};
+struct StdStringEqualsNoCaseA
+ : std::binary_function<CStdStringA, CStdStringA, bool>
+{
+ inline
+ bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const
+ { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }
+};
+
+// If we had to define our own version of TRACE above, get rid of it now
+
+#ifdef TRACE_DEFINED_HERE
+ #undef TRACE
+ #undef TRACE_DEFINED_HERE
+#endif
+
+
+// These std::swap specializations come courtesy of Mike Crusader.
+
+//namespace std
+//{
+// inline void swap(CStdStringA& s1, CStdStringA& s2) throw()
+// {
+// s1.swap(s2);
+// }
+// template<>
+// inline void swap(CStdStringW& s1, CStdStringW& s2) throw()
+// {
+// s1.swap(s2);
+// }
+//}
+
+// Turn back on any Borland warnings we turned off.
+
+#ifdef __BORLANDC__
+ #pragma option pop // Turn back on inline function warnings
+// #pragma warn +inl // Turn back on inline function warnings
+#endif
+
+#endif // #ifndef STDSTRING_H
+
diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h
new file mode 100644
index 0000000..8d41a10
--- /dev/null
+++ b/orkbasecxx/Utils.h
@@ -0,0 +1,93 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include "ace/Guard_T.h" // For some reason, this include must always come before the StdString include
+ // otherwise it gives the following compile error:
+ // error C2039: 'TryEnterCriticalSection' : is not a member of '`global namespace''
+ // If seeing this error somewhere, the remedy is to #include "Utils.h" first
+#include "ace/Thread_Mutex.h"
+#include "StdString.h"
+
+#include "OrkBase.h"
+
+inline CStdString IntToString(int integer)
+{
+ CStdString ret;
+ ret.Format("%d", integer);
+ return ret;
+}
+
+inline int StringToInt(CStdString& value)
+{
+ char* errorLocation = NULL;
+ PCSTR szValue = (PCSTR)value;
+ int intValue = strtol(szValue, &errorLocation, 10);
+ if(*errorLocation != '\0')
+ throw CStdString(CStdString("StringToInt: invalid integer:") + value);
+ return intValue;
+}
+
+inline CStdString DoubleToString(double value)
+{
+ CStdString ret;
+ ret.Format("%f", value);
+ return ret;
+}
+
+inline double StringToDouble(CStdString& value)
+{
+ char* errorLocation = NULL;
+ PCSTR szValue = (PCSTR)value;
+ double doubleValue = strtod(szValue, &errorLocation);
+ if(errorLocation == szValue)
+ throw CStdString(CStdString("StringToDouble: invalid double:") + value);
+ return doubleValue;
+}
+
+inline CStdString BaseName(CStdString& path)
+{
+ CStdString result;
+ int lastSeparatorPosition = path.ReverseFind('/');
+ if(lastSeparatorPosition == -1)
+ {
+ lastSeparatorPosition = path.ReverseFind('\\');
+ }
+ if(lastSeparatorPosition != -1 && path.GetLength()>3)
+ {
+ result = path.Right(path.GetLength() - lastSeparatorPosition - 1);
+ }
+ return result;
+}
+
+inline CStdString StripFileExtension(CStdString& filename)
+{
+ CStdString result;
+ int extensionPosition = filename.ReverseFind('.');
+ if (extensionPosition != -1)
+ {
+ result = filename.Left(extensionPosition);
+ }
+ else
+ {
+ result = filename;
+ }
+ return result;
+}
+
+typedef ACE_Guard<ACE_Thread_Mutex> MutexSentinel;
+
+#endif
+
diff --git a/orkbasecxx/config.guess b/orkbasecxx/config.guess
new file mode 100644
index 0000000..182e141
--- /dev/null
+++ b/orkbasecxx/config.guess
@@ -0,0 +1 @@
+link /usr/share/libtool/config.guess \ No newline at end of file
diff --git a/orkbasecxx/config.sub b/orkbasecxx/config.sub
new file mode 100644
index 0000000..ea4beb2
--- /dev/null
+++ b/orkbasecxx/config.sub
@@ -0,0 +1 @@
+link /usr/share/libtool/config.sub \ No newline at end of file
diff --git a/orkbasecxx/configure.in b/orkbasecxx/configure.in
new file mode 100644
index 0000000..fae8c6e
--- /dev/null
+++ b/orkbasecxx/configure.in
@@ -0,0 +1,10 @@
+AC_INIT(configure.in)
+
+AM_CONFIG_HEADER(config.h)
+AM_INIT_AUTOMAKE(orkbase, 0.1)
+
+AC_LANG_CPLUSPLUS
+AC_PROG_CXX
+AM_PROG_LIBTOOL
+
+AC_OUTPUT(Makefile messages/Makefile serializers/Makefile)
diff --git a/orkbasecxx/install-sh b/orkbasecxx/install-sh
new file mode 100644
index 0000000..36f96f3
--- /dev/null
+++ b/orkbasecxx/install-sh
@@ -0,0 +1,276 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. M.I.T. makes no representations about the
+# suitability of this software for any purpose. It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch. It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd=$cpprog
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd=$stripprog
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "$0: no input file specified" >&2
+ exit 1
+else
+ :
+fi
+
+if [ x"$dir_arg" != x ]; then
+ dst=$src
+ src=""
+
+ if [ -d "$dst" ]; then
+ instcmd=:
+ chmodcmd=""
+ else
+ instcmd=$mkdirprog
+ fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+ if [ -f "$src" ] || [ -d "$src" ]
+ then
+ :
+ else
+ echo "$0: $src does not exist" >&2
+ exit 1
+ fi
+
+ if [ x"$dst" = x ]
+ then
+ echo "$0: no destination specified" >&2
+ exit 1
+ else
+ :
+ fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+ if [ -d "$dst" ]
+ then
+ dst=$dst/`basename "$src"`
+ else
+ :
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+ '
+IFS="${IFS-$defaultIFS}"
+
+oIFS=$IFS
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS=$oIFS
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+ pathcomp=$pathcomp$1
+ shift
+
+ if [ ! -d "$pathcomp" ] ;
+ then
+ $mkdirprog "$pathcomp"
+ else
+ :
+ fi
+
+ pathcomp=$pathcomp/
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+ $doit $instcmd "$dst" &&
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+ if [ x"$transformarg" = x ]
+ then
+ dstfile=`basename "$dst"`
+ else
+ dstfile=`basename "$dst" $transformbasename |
+ sed $transformarg`$transformbasename
+ fi
+
+# don't allow the sed command to completely eliminate the filename
+
+ if [ x"$dstfile" = x ]
+ then
+ dstfile=`basename "$dst"`
+ else
+ :
+ fi
+
+# Make a couple of temp file names in the proper directory.
+
+ dsttmp=$dstdir/#inst.$$#
+ rmtmp=$dstdir/#rm.$$#
+
+# Trap to clean up temp files at exit.
+
+ trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
+ trap '(exit $?); exit' 1 2 13 15
+
+# Move or copy the file name to the temp name
+
+ $doit $instcmd "$src" "$dsttmp" &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing. If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
+
+# Now remove or move aside any old file at destination location. We try this
+# two ways since rm can't unlink itself on some systems and the destination
+# file might be busy for other reasons. In this case, the final cleanup
+# might fail but the new file should still install successfully.
+
+{
+ if [ -f "$dstdir/$dstfile" ]
+ then
+ $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
+ $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
+ {
+ echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+ (exit 1); exit
+ }
+ else
+ :
+ fi
+} &&
+
+# Now rename the file to the real destination.
+
+ $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+
+fi &&
+
+# The final little trick to "correctly" pass the exit status to the exit trap.
+
+{
+ (exit 0); exit
+}
diff --git a/orkbasecxx/ltmain.sh b/orkbasecxx/ltmain.sh
new file mode 100644
index 0000000..7404ae3
--- /dev/null
+++ b/orkbasecxx/ltmain.sh
@@ -0,0 +1 @@
+link /usr/share/libtool/ltmain.sh \ No newline at end of file
diff --git a/orkbasecxx/messages/AsyncMessage.cpp b/orkbasecxx/messages/AsyncMessage.cpp
new file mode 100644
index 0000000..e32cb50
--- /dev/null
+++ b/orkbasecxx/messages/AsyncMessage.cpp
@@ -0,0 +1,46 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "AsyncMessage.h"
+
+//void AsyncMessage::send(XmlRpc::XmlRpcClient& c)
+//{
+// ;
+//}
+
+#define SIMPLERESPONSE_CLASS "simpleresponse"
+#define SUCCESS_PARAM "sucess"
+#define SUCCESS_DEFAULT true
+#define COMMENT_PARAM "comment"
+
+SimpleResponseMsg::SimpleResponseMsg()
+{
+ m_success = false;
+}
+
+
+void SimpleResponseMsg::Define(Serializer* s)
+{
+ s->BoolValue(SUCCESS_PARAM, m_success);
+ s->StringValue(COMMENT_PARAM, m_comment);
+}
+
+CStdString SimpleResponseMsg::GetClassName()
+{
+ return CStdString(SIMPLERESPONSE_CLASS);
+}
+
+ObjectRef SimpleResponseMsg::NewInstance()
+{
+ return ObjectRef(new SimpleResponseMsg);
+}
diff --git a/orkbasecxx/messages/AsyncMessage.h b/orkbasecxx/messages/AsyncMessage.h
new file mode 100644
index 0000000..bbdb313
--- /dev/null
+++ b/orkbasecxx/messages/AsyncMessage.h
@@ -0,0 +1,48 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __ASYNCMESSAGE_H__
+#define __ASYNCMESSAGE_H__
+
+//#include "XmlRpc.h"
+#include "Message.h"
+
+/** An AsyncMessage is an asynchronous message ("fire and forget").
+ It can also be the response to a synchronous message.
+*/
+class DLL_IMPORT_EXPORT AsyncMessage : public Message
+{
+//public:
+// void send(XmlRpc::XmlRpcClient& c);
+};
+
+/** A SimpleResponseMsg is used as a response when commands can just succeed or fail.
+ Additionally, there is textual comment field e.g. for error messages.
+*/
+class DLL_IMPORT_EXPORT SimpleResponseMsg : public AsyncMessage
+{
+public:
+ SimpleResponseMsg();
+ void Define(Serializer* s);
+ inline void Validate() {};
+
+ CStdString GetClassName();
+ ObjectRef NewInstance();
+ inline ObjectRef Process() {return ObjectRef();};
+
+ bool m_success;
+ CStdString m_comment;
+};
+
+#endif
+
diff --git a/orkbasecxx/messages/Makefile.am b/orkbasecxx/messages/Makefile.am
new file mode 100644
index 0000000..0465da7
--- /dev/null
+++ b/orkbasecxx/messages/Makefile.am
@@ -0,0 +1,8 @@
+METASOURCES = AUTO
+noinst_LTLIBRARIES = libmessages.la
+libmessages_la_SOURCES = AsyncMessage.cpp AsyncMessage.h Message.cpp Message.h\
+ SyncMessage.cpp SyncMessage.h
+
+#libmessages_la_LIBADD = -L/projects/ext/xmlrpc++/xmlrpc++0.7/ -lXmlRpc
+INCLUDES = -I@top_srcdir@
+AM_CXXFLAGS = -D_REENTRANT
diff --git a/orkbasecxx/messages/Message.cpp b/orkbasecxx/messages/Message.cpp
new file mode 100644
index 0000000..ad6e533
--- /dev/null
+++ b/orkbasecxx/messages/Message.cpp
@@ -0,0 +1,41 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning
+
+#include "serializers/XmlRpcSerializer.h"
+#include "Message.h"
+
+
+char Message::m_hostname[HOSTNAME_BUF_LEN] = "";
+
+Message::Message()
+{
+ m_creationTime = time(NULL);
+ ACE_OS::hostname(m_hostname, HOSTNAME_BUF_LEN);
+}
+
+
+bool Message::InvokeXmlRpc(CStdString& hostname, int tcpPort)
+{
+/*
+ XmlRpcSerializer serializer(this);
+ return serializer.Invoke(hostname, tcpPort);
+ //serializerRef.reset(new XmlRpcSerializer(this));
+ //serializerRef->Invoke(hostname, tcpPort);
+*/
+ return true;
+}
+
diff --git a/orkbasecxx/messages/Message.h b/orkbasecxx/messages/Message.h
new file mode 100644
index 0000000..1ecceb6
--- /dev/null
+++ b/orkbasecxx/messages/Message.h
@@ -0,0 +1,55 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __MESSAGE_H__
+#define __MESSAGE_H__
+
+//#ifdef WIN32
+#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning
+#pragma warning( disable: 4018 ) // signed/unsigned mismatch
+//#endif
+
+#include "OrkBase.h"
+#include "ace/OS_NS_time.h"
+#include "ace/OS_NS_unistd.h"
+
+#include "serializers/Serializer.h"
+#include "Object.h"
+
+#define HOSTNAME_BUF_LEN 40
+
+#define TIMESTAMP_PARAM "timestamp"
+#define CAPTURE_PORT_PARAM "captureport"
+#define FILENAME_PARAM "filename"
+
+#define SUCCESS_PARAM "sucess"
+#define SUCCESS_DEFAULT true
+
+/** A Message is an Object that is meant to be sent to a remote server.
+*/
+class DLL_IMPORT_EXPORT Message : public Object
+{
+public:
+ Message();
+
+ bool InvokeXmlRpc(CStdString& hostname, int tcpport);
+protected:
+ time_t m_creationTime;
+ bool m_sent;
+ static char m_hostname[HOSTNAME_BUF_LEN];
+};
+
+typedef boost::shared_ptr<Message> MessageRef;
+
+#endif
+
diff --git a/orkbasecxx/messages/SyncMessage.cpp b/orkbasecxx/messages/SyncMessage.cpp
new file mode 100644
index 0000000..b49fd64
--- /dev/null
+++ b/orkbasecxx/messages/SyncMessage.cpp
@@ -0,0 +1,14 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "SyncMessage.h"
diff --git a/orkbasecxx/messages/SyncMessage.h b/orkbasecxx/messages/SyncMessage.h
new file mode 100644
index 0000000..598ffe3
--- /dev/null
+++ b/orkbasecxx/messages/SyncMessage.h
@@ -0,0 +1,31 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma warning( disable: 4786 )
+
+#ifndef __SYNCMESSAGE_H__
+#define __SYNCMESSAGE_H__
+
+
+#include "Message.h"
+
+/** A SyncMessage is a synchronous message that needs an immediate answer from the remote server.
+ The response should be an AsyncMessage
+*/
+class DLL_IMPORT_EXPORT SyncMessage : public Message
+{
+public:
+};
+
+#endif
+
diff --git a/orkbasecxx/missing b/orkbasecxx/missing
new file mode 100644
index 0000000..6a37006
--- /dev/null
+++ b/orkbasecxx/missing
@@ -0,0 +1,336 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+ echo 1>&2 "Try \`$0 --help' for more information"
+ exit 1
+fi
+
+run=:
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+ configure_ac=configure.ac
+else
+ configure_ac=configure.in
+fi
+
+case "$1" in
+--run)
+ # Try to run requested program, and just exit if it succeeds.
+ run=
+ shift
+ "$@" && exit 0
+ ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case "$1" in
+
+ -h|--h|--he|--hel|--help)
+ echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+ -h, --help display this help and exit
+ -v, --version output version information and exit
+ --run try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+ aclocal touch file \`aclocal.m4'
+ autoconf touch file \`configure'
+ autoheader touch file \`config.h.in'
+ automake touch all \`Makefile.in' files
+ bison create \`y.tab.[ch]', if possible, from existing .[ch]
+ flex create \`lex.yy.c', if possible, from existing .c
+ help2man touch the output file
+ lex create \`lex.yy.c', if possible, from existing .c
+ makeinfo touch the output file
+ tar try tar, gnutar, gtar, then tar without non-portable flags
+ yacc create \`y.tab.[ch]', if possible, from existing .[ch]"
+ ;;
+
+ -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+ echo "missing 0.4 - GNU automake"
+ ;;
+
+ -*)
+ echo 1>&2 "$0: Unknown \`$1' option"
+ echo 1>&2 "Try \`$0 --help' for more information"
+ exit 1
+ ;;
+
+ aclocal*)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`acinclude.m4' or \`${configure_ac}'. You might want
+ to install the \`Automake' and \`Perl' packages. Grab them from
+ any GNU archive site."
+ touch aclocal.m4
+ ;;
+
+ autoconf)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`${configure_ac}'. You might want to install the
+ \`Autoconf' and \`GNU m4' packages. Grab them from any GNU
+ archive site."
+ touch configure
+ ;;
+
+ autoheader)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`acconfig.h' or \`${configure_ac}'. You might want
+ to install the \`Autoconf' and \`GNU m4' packages. Grab them
+ from any GNU archive site."
+ files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+ test -z "$files" && files="config.h"
+ touch_files=
+ for f in $files; do
+ case "$f" in
+ *:*) touch_files="$touch_files "`echo "$f" |
+ sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+ *) touch_files="$touch_files $f.in";;
+ esac
+ done
+ touch $touch_files
+ ;;
+
+ automake*)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+ You might want to install the \`Automake' and \`Perl' packages.
+ Grab them from any GNU archive site."
+ find . -type f -name Makefile.am -print |
+ sed 's/\.am$/.in/' |
+ while read f; do touch "$f"; done
+ ;;
+
+ autom4te)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is needed, and you do not seem to have it handy on your
+ system. You might have modified some files without having the
+ proper tools for further handling them.
+ You can get \`$1Help2man' as part of \`Autoconf' from any GNU
+ archive site."
+
+ file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
+ test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
+ if test -f "$file"; then
+ touch $file
+ else
+ test -z "$file" || exec >$file
+ echo "#! /bin/sh"
+ echo "# Created by GNU Automake missing as a replacement of"
+ echo "# $ $@"
+ echo "exit 0"
+ chmod +x $file
+ exit 1
+ fi
+ ;;
+
+ bison|yacc)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.y' file. You may need the \`Bison' package
+ in order for those modifications to take effect. You can get
+ \`Bison' from any GNU archive site."
+ rm -f y.tab.c y.tab.h
+ if [ $# -ne 1 ]; then
+ eval LASTARG="\${$#}"
+ case "$LASTARG" in
+ *.y)
+ SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" y.tab.c
+ fi
+ SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" y.tab.h
+ fi
+ ;;
+ esac
+ fi
+ if [ ! -f y.tab.h ]; then
+ echo >y.tab.h
+ fi
+ if [ ! -f y.tab.c ]; then
+ echo 'main() { return 0; }' >y.tab.c
+ fi
+ ;;
+
+ lex|flex)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.l' file. You may need the \`Flex' package
+ in order for those modifications to take effect. You can get
+ \`Flex' from any GNU archive site."
+ rm -f lex.yy.c
+ if [ $# -ne 1 ]; then
+ eval LASTARG="\${$#}"
+ case "$LASTARG" in
+ *.l)
+ SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" lex.yy.c
+ fi
+ ;;
+ esac
+ fi
+ if [ ! -f lex.yy.c ]; then
+ echo 'main() { return 0; }' >lex.yy.c
+ fi
+ ;;
+
+ help2man)
+ if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+ # We have it, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a dependency of a manual page. You may need the
+ \`Help2man' package in order for those modifications to take
+ effect. You can get \`Help2man' from any GNU archive site."
+
+ file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+ if test -z "$file"; then
+ file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
+ fi
+ if [ -f "$file" ]; then
+ touch $file
+ else
+ test -z "$file" || exec >$file
+ echo ".ab help2man is required to generate this page"
+ exit 1
+ fi
+ ;;
+
+ makeinfo)
+ if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
+ # We have makeinfo, but it failed.
+ exit 1
+ fi
+
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.texi' or \`.texinfo' file, or any other file
+ indirectly affecting the aspect of the manual. The spurious
+ call might also be the consequence of using a buggy \`make' (AIX,
+ DU, IRIX). You might want to install the \`Texinfo' package or
+ the \`GNU make' package. Grab either from any GNU archive site."
+ file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+ if test -z "$file"; then
+ file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+ file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+ fi
+ touch $file
+ ;;
+
+ tar)
+ shift
+ if test -n "$run"; then
+ echo 1>&2 "ERROR: \`tar' requires --run"
+ exit 1
+ fi
+
+ # We have already tried tar in the generic part.
+ # Look for gnutar/gtar before invocation to avoid ugly error
+ # messages.
+ if (gnutar --version > /dev/null 2>&1); then
+ gnutar "$@" && exit 0
+ fi
+ if (gtar --version > /dev/null 2>&1); then
+ gtar "$@" && exit 0
+ fi
+ firstarg="$1"
+ if shift; then
+ case "$firstarg" in
+ *o*)
+ firstarg=`echo "$firstarg" | sed s/o//`
+ tar "$firstarg" "$@" && exit 0
+ ;;
+ esac
+ case "$firstarg" in
+ *h*)
+ firstarg=`echo "$firstarg" | sed s/h//`
+ tar "$firstarg" "$@" && exit 0
+ ;;
+ esac
+ fi
+
+ echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+ You may want to install GNU tar or Free paxutils, or check the
+ command line arguments."
+ exit 1
+ ;;
+
+ *)
+ echo 1>&2 "\
+WARNING: \`$1' is needed, and you do not seem to have it handy on your
+ system. You might have modified some files without having the
+ proper tools for further handling them. Check the \`README' file,
+ it often tells you about the needed prerequirements for installing
+ this package. You may also peek at any GNU archive site, in case
+ some other package would contain this missing \`$1' program."
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/orkbasecxx/mkinstalldirs b/orkbasecxx/mkinstalldirs
new file mode 100644
index 0000000..d2d5f21
--- /dev/null
+++ b/orkbasecxx/mkinstalldirs
@@ -0,0 +1,111 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+errstatus=0
+dirmode=""
+
+usage="\
+Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
+
+# process command line arguments
+while test $# -gt 0 ; do
+ case $1 in
+ -h | --help | --h*) # -h for help
+ echo "$usage" 1>&2
+ exit 0
+ ;;
+ -m) # -m PERM arg
+ shift
+ test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+ dirmode=$1
+ shift
+ ;;
+ --) # stop option processing
+ shift
+ break
+ ;;
+ -*) # unknown option
+ echo "$usage" 1>&2
+ exit 1
+ ;;
+ *) # first non-opt arg
+ break
+ ;;
+ esac
+done
+
+for file
+do
+ if test -d "$file"; then
+ shift
+ else
+ break
+ fi
+done
+
+case $# in
+ 0) exit 0 ;;
+esac
+
+case $dirmode in
+ '')
+ if mkdir -p -- . 2>/dev/null; then
+ echo "mkdir -p -- $*"
+ exec mkdir -p -- "$@"
+ fi
+ ;;
+ *)
+ if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+ echo "mkdir -m $dirmode -p -- $*"
+ exec mkdir -m "$dirmode" -p -- "$@"
+ fi
+ ;;
+esac
+
+for file
+do
+ set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ shift
+
+ pathcomp=
+ for d
+ do
+ pathcomp="$pathcomp$d"
+ case $pathcomp in
+ -*) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp"
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ else
+ if test ! -z "$dirmode"; then
+ echo "chmod $dirmode $pathcomp"
+ lasterr=""
+ chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+ if test ! -z "$lasterr"; then
+ errstatus=$lasterr
+ fi
+ fi
+ fi
+ fi
+
+ pathcomp="$pathcomp/"
+ done
+done
+
+exit $errstatus
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# End:
+# mkinstalldirs ends here
diff --git a/orkbasecxx/serializers/DomSerializer.cpp b/orkbasecxx/serializers/DomSerializer.cpp
new file mode 100644
index 0000000..348819e
--- /dev/null
+++ b/orkbasecxx/serializers/DomSerializer.cpp
@@ -0,0 +1,157 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "xercesc/util/XMLString.hpp"
+#include <xercesc/util/PlatformUtils.hpp>
+#include <xercesc/dom/DOM.hpp>
+#include <xercesc/dom/DOMElement.hpp>
+#include <xercesc/dom/DOMImplementation.hpp>
+#include <xercesc/dom/DOMImplementationLS.hpp>
+#include <xercesc/dom/DOMWriter.hpp>
+#include <xercesc/framework/MemBufFormatTarget.hpp>
+
+#include "DomSerializer.h"
+
+void DomSerializer::ObjectValue(const char* key, Object& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetObject(key, value, required);
+ }
+ else
+ {
+ AddObject(key, value);
+ }
+}
+
+void DomSerializer::GetString(const char* key, CStdString& value, bool required)
+{
+ // Find the right node
+ DOMNode* stringNode = FindElementByName(m_node, CStdString(key));
+
+ if(stringNode)
+ {
+ // Now, the string associated to element should be the first child (text element)
+ DOMNode* textNode = stringNode->getFirstChild();
+ if (textNode && textNode->getNodeType() == DOMNode::TEXT_NODE)
+ {
+ value = XMLStringToLocal(textNode->getNodeValue());
+ }
+ }
+ else if (required)
+ {
+ throw(CStdString("DomSerializer::GetString: required parameter missing:") + key);
+ }
+}
+
+void DomSerializer::GetObject(const char* key, Object& value, bool required)
+{
+ // Find the node corresponding to the object wanting to be populated
+ DOMNode* objectNode = FindElementByName(m_node, CStdString(key));
+
+ // Create a new serializer and affect it to this object
+ if (objectNode)
+ {
+ DomSerializer serializer(&value);
+ serializer.DeSerialize(objectNode);
+ }
+ else if (required)
+ {
+ throw(CStdString("DomSerializer::GetObject: required node missing:") + key);
+ }
+}
+
+void DomSerializer::AddObject(const char* key, Object& value)
+{
+ ;
+}
+
+void DomSerializer::AddString(const char* key, CStdString& value)
+{
+ DOMElement* newElem = m_document->createElement(XStr(key).unicodeForm());
+ m_node->appendChild(newElem);
+
+ DOMText* newText = m_document->createTextNode(XStr((PCSTR)value).unicodeForm());
+ newElem->appendChild(newText);
+}
+
+void DomSerializer::Serialize(XERCES_CPP_NAMESPACE::DOMDocument* doc)
+{
+ if(doc)
+ {
+ m_document = doc;
+ m_node = m_document->getDocumentElement();
+ m_deSerialize = false; // Set Serialize mode
+ m_object->Define(this);
+ }
+ else
+ {
+ throw(CStdString("DomSerializer::Serialize: input DOM document is NULL"));
+ }
+}
+
+void DomSerializer::DeSerialize(DOMNode* node)
+{
+ m_node = node;
+ m_deSerialize = true; // Set DeSerialize mode
+ m_object->Define(this);
+ m_object->Validate();
+}
+
+CStdString DomSerializer::XMLStringToLocal(const XMLCh* const toTranscode)
+{
+ char* szResult = XMLString::transcode(toTranscode);
+ CStdString result = szResult;
+ XMLString::release(&szResult);
+ return result;
+}
+
+DOMNode* DomSerializer::FindElementByName(DOMNode *node, CStdString name)
+{
+ DOMNode *child = node->getFirstChild();
+ while(child)
+ {
+ if (XMLStringToLocal(child->getNodeName()) == name && child->getNodeType() == DOMNode::ELEMENT_NODE)
+ {
+ return child;
+ }
+ child = child->getNextSibling();
+ }
+ return NULL;
+}
+
+CStdString DomSerializer::DomNodeToString(DOMNode* node)
+{
+ CStdString output;
+
+ DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XStr("LS").unicodeForm());
+ DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
+ // set user specified output encoding
+ //theSerializer->setEncoding(gOutputEncoding);
+ theSerializer->setFeature(XStr("format-pretty-print").unicodeForm(), true);
+
+ XMLFormatTarget *myFormTarget;
+ myFormTarget = new MemBufFormatTarget ();
+ theSerializer->writeNode(myFormTarget, *node);
+
+ output = (char *)((MemBufFormatTarget*)myFormTarget)->getRawBuffer();
+
+ // Clean up
+ delete theSerializer;
+ //
+ // Filter, formatTarget and error handler
+ // are NOT owned by the serializer.
+ delete myFormTarget;
+
+ return output;
+}
diff --git a/orkbasecxx/serializers/DomSerializer.h b/orkbasecxx/serializers/DomSerializer.h
new file mode 100644
index 0000000..4190d59
--- /dev/null
+++ b/orkbasecxx/serializers/DomSerializer.h
@@ -0,0 +1,81 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __DOMSERIALIZER_H__
+#define __DOMSERIALIZER_H__
+
+#include "Serializer.h"
+#include "Object.h"
+
+#include "xercesc/dom/DOMNode.hpp"
+#include "xercesc/util/XMLString.hpp"
+
+using namespace XERCES_CPP_NAMESPACE;
+
+/** Serializer class for Document Object Model.
+ This class allows a nested object to be serialized or deserialized
+ to or from a xerces DOM object.
+*/
+class DLL_IMPORT_EXPORT DomSerializer : public Serializer
+{
+public:
+ DomSerializer(Object* object) : Serializer(object){};
+
+ void ObjectValue(const char* key, Object& value, bool required = false);
+
+ void AddInt(const char* key, int value);
+ void AddString(const char* key, CStdString& value);
+ void AddObject(const char* key, Object& value);
+ void Serialize(XERCES_CPP_NAMESPACE::DOMDocument* node);
+
+ void GetString(const char* key, CStdString& value, bool required = false);
+ void GetObject(const char* key, Object& value, bool required = false);
+ void DeSerialize(DOMNode* node);
+
+ static CStdString XMLStringToLocal(const XMLCh* const toTranscode);
+ static XMLCh* LocalStringToXML(CStdString& toTranscode);
+
+ DOMNode* FindElementByName(DOMNode *node, CStdString name);
+
+ static CStdString DomNodeToString(DOMNode *);
+protected:
+ DOMNode* m_node;
+ XERCES_CPP_NAMESPACE::DOMDocument* m_document;
+};
+
+/** Container for xerces unicode string initialized with char* string */
+class DLL_IMPORT_EXPORT XStr
+{
+public :
+ inline XStr(const char* const toTranscode)
+ {
+ fUnicodeForm = XMLString::transcode(toTranscode);
+ }
+
+ inline ~XStr()
+ {
+ XMLString::release(&fUnicodeForm);
+ }
+
+ inline const XMLCh* unicodeForm() const
+ {
+ return fUnicodeForm;
+ }
+
+private :
+ XMLCh* fUnicodeForm;
+};
+
+
+#endif
+
diff --git a/orkbasecxx/serializers/Makefile.am b/orkbasecxx/serializers/Makefile.am
new file mode 100644
index 0000000..33bd167
--- /dev/null
+++ b/orkbasecxx/serializers/Makefile.am
@@ -0,0 +1,10 @@
+METASOURCES = AUTO
+noinst_LTLIBRARIES = libserializers.la
+libserializers_la_SOURCES = DomSerializer.cpp DomSerializer.h Serializer.cpp\
+ Serializer.h SingleLineSerializer.cpp SingleLineSerializer.h\
+ UrlSerializer.cpp UrlSerializer.h XmlRpcSerializer.cpp\
+ XmlRpcSerializer.h
+#libserializers_la_LIBADD = -L/projects/ext/xmlrpc++/xmlrpc++0.7/ -lXmlRpc
+INCLUDES = -I@top_srcdir@
+
+AM_CXXFLAGS = -D_REENTRANT
diff --git a/orkbasecxx/serializers/Serializer.cpp b/orkbasecxx/serializers/Serializer.cpp
new file mode 100644
index 0000000..8e571ed
--- /dev/null
+++ b/orkbasecxx/serializers/Serializer.cpp
@@ -0,0 +1,312 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#define _WINSOCKAPI_ // prevents the inclusion of winsock.h
+
+#include "ace/OS_NS_time.h"
+#include "Object.h"
+#include "Serializer.h"
+#include "Utils.h"
+
+using namespace XERCES_CPP_NAMESPACE;
+
+Serializer::Serializer(Object* object)
+{
+ m_object = object;
+}
+
+void Serializer::IntValue(const char* key, int& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetInt(key, value, required);
+ }
+ else
+ {
+ AddInt(key, value);
+ }
+}
+
+void Serializer::DoubleValue(const char* key, double& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetDouble(key, value, required);
+ }
+ else
+ {
+ AddDouble(key, value);
+ }
+}
+
+void Serializer::BoolValue(const char* key, bool& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetBool(key, value, required);
+ }
+ else
+ {
+ AddBool(key, value);
+ }
+}
+
+void Serializer::StringValue(const char* key, CStdString& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetString(key, value, required);
+ }
+ else
+ {
+ AddString(key, value);
+ }
+}
+
+void Serializer::EnumValue(const char* key, int& value, StringToEnumFunction toEnum, EnumToStringFunction toString, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetEnum(key, value, toEnum, required);
+ }
+ else
+ {
+ AddEnum(key, value, toString);
+ }
+}
+
+void Serializer::CsvValue(const char* key, std::list<CStdString>& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetCsv(key, value, required);
+ }
+ else
+ {
+ AddCsv(key, value);
+ }
+}
+
+void Serializer::DateValue(const char* key, time_t& value, bool required)
+{
+ if (m_deSerialize == true)
+ {
+ GetDate(key, value, required);
+ }
+ else
+ {
+ AddDate(key, value);
+ }
+}
+
+
+//=====================================
+void Serializer::AddInt(const char* key, int value)
+{
+ CStdString valueString = IntToString(value);
+ AddString(key, valueString);
+}
+
+void Serializer::AddDouble(const char* key, double value)
+{
+ CStdString valueString = DoubleToString(value);
+ AddString(key, valueString);
+}
+
+void Serializer::AddBool(const char* key, bool value)
+{
+ if(value)
+ {
+ CStdString trueString("true");
+ AddString(key, trueString);
+ }
+ else
+ {
+ CStdString falseString("false");
+ AddString(key, falseString);
+ }
+}
+
+void Serializer::AddEnum(const char* key, int value, EnumToStringFunction function)
+{
+ if(!function)
+ {
+ throw(CStdString("Serializer: wrong enumerated type conversion function for parameter:") + key);
+ }
+ else
+ {
+ CStdString valueString = function(value);
+ AddString(key, valueString);
+ }
+}
+
+void Serializer::AddCsv(const char* key, std::list<CStdString>& value)
+{
+ CStdString csvString;
+ bool first = true;
+ for(std::list<CStdString>::iterator it = value.begin(); it!=value.end(); it++)
+ {
+ if(!first)
+ {
+ csvString += ",";
+ }
+ first = false;
+ csvString += *it;
+ }
+ AddString(key, csvString);
+}
+
+void Serializer::AddDate(const char* key, time_t value)
+{
+ struct tm date;
+ ACE_OS::localtime_r(&value ,&date);
+ int month = date.tm_mon + 1; // january=0, decembre=11
+ int year = date.tm_year + 1900;
+ CStdString dateString;
+ dateString.Format("%.4d-%.2d-%.2d_%.2d-%.2d-%.2d", year, month, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
+ AddString(key, dateString);
+}
+
+
+//====================================================================
+void Serializer::GetInt(const char* key, int&value, bool required)
+{
+ CStdString stringValue;
+ GetString(key, stringValue, required);
+ if(!stringValue.IsEmpty())
+ {
+ value = StringToInt(stringValue);
+ }
+}
+
+void Serializer::GetDouble(const char* key, double&value, bool required)
+{
+ CStdString stringValue;
+ GetString(key, stringValue, required);
+ if(!stringValue.IsEmpty())
+ {
+ value = StringToDouble(stringValue);
+ }
+}
+
+void Serializer::GetBool(const char* key, bool&value, bool required)
+{
+ CStdString stringValue;
+ GetString(key, stringValue, required);
+ stringValue.ToLower();
+ if( stringValue == "true" || stringValue == "yes" || stringValue == "1" )
+ {
+ value = true;
+ }
+ else if( stringValue == "false" || stringValue == "no" || stringValue == "0" )
+ {
+ value = false;
+ }
+ else if( stringValue.IsEmpty() )
+ {
+ ; // do not touch default value
+ }
+ else
+ {
+ throw(CStdString("Serializer: Invalid boolean value:") + stringValue + " for parameter:" + key);
+ }
+}
+
+void Serializer::GetEnum(const char* key, int& value, StringToEnumFunction function, bool required)
+{
+ if(!function)
+ {
+ throw(CStdString("Serializer: missing enumerated type conversion function for parameter:") + key);
+ }
+ else
+ {
+ CStdString enumStringValue;
+ GetString(key, enumStringValue, required);
+ if (!enumStringValue.IsEmpty())
+ {
+ value = function(enumStringValue);
+ }
+ }
+
+}
+
+void Serializer::GetCsv(const char* key, std::list<CStdString>& value, bool required)
+{
+ CStdString stringValue;
+ stringValue.Trim();
+ CStdString element;
+ bool first = true;
+ GetString(key, stringValue, required);
+ for(int i=0; i<stringValue.length(); i++)
+ {
+ TCHAR c = stringValue[i];
+ if(c == ',')
+ {
+ if(first)
+ {
+ first = false; // only erase default value if something found
+ value.clear();
+ }
+ element.Trim();
+ value.push_back(element);
+ element.Empty();
+ }
+ else
+ {
+ element += c;
+ }
+ }
+ if (!element.IsEmpty())
+ {
+ if(first)
+ {
+ first = false; // only erase default value if something found
+ value.clear();
+ }
+ element.Trim();
+ value.push_back(element);
+ }
+}
+
+void Serializer::GetDate(const char* key, time_t& value, bool required)
+{
+ throw (CStdString("DeSerializer: GetDate: not implemented yet"));
+
+ CStdString stringValue;
+ GetString(key, stringValue, required);
+ if(!stringValue.IsEmpty())
+ {
+ //value = ;
+ }
+}
+
+//==========================================================
+
+void KeyValueSerializer::GetString(const char* key, CStdString& value, bool required)
+{
+ std::map<CStdString, CStdString>::iterator it = m_map.find(CStdString(key));
+ if (it != m_map.end())
+ {
+ value = it->second;
+ }
+ else if (required == true)
+ {
+ throw CStdString(CStdString("Serializer::GetString: required parameter missing:") + key);
+ }
+}
+
+void KeyValueSerializer::ObjectValue(const char* key, Object& value, bool required)
+{
+ throw CStdString(CStdString("KeyValueSerializer::ObjectValue: Nested objects not allowed for key-value serializers"));
+}
+
diff --git a/orkbasecxx/serializers/Serializer.h b/orkbasecxx/serializers/Serializer.h
new file mode 100644
index 0000000..a63af1a
--- /dev/null
+++ b/orkbasecxx/serializers/Serializer.h
@@ -0,0 +1,86 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __SERIALIZER_H__
+#define __SERIALIZER_H__
+
+#pragma warning( disable: 4786 ) // disables truncated symbols in browse-info warning
+
+#include "OrkBase.h"
+#include <map>
+#include <list>
+#include "boost/shared_ptr.hpp"
+
+typedef int (*StringToEnumFunction)(CStdString&);
+typedef CStdString (*EnumToStringFunction)(int);
+
+class Object;
+
+/** Base class for serializing Objects.
+*/
+class DLL_IMPORT_EXPORT Serializer
+{
+public:
+ Serializer(Object* object);
+
+ void IntValue(const char* key, int& value, bool required = false);
+ void DoubleValue(const char* key, double& value, bool required = false);
+ void StringValue(const char* key, CStdString& value, bool required = false);
+ void BoolValue(const char* key, bool& value, bool required = false);
+ void EnumValue(const char* key, int& value, StringToEnumFunction, EnumToStringFunction, bool required = false);
+ virtual void ObjectValue(const char* key, Object& value, bool required = false) = 0;
+ void CsvValue(const char* key, std::list<CStdString>& value, bool required = false);
+ void DateValue(const char* key, time_t& value, bool required = false);
+
+ void AddInt(const char* key, int value);
+ void AddDouble(const char* key, double value);
+ void AddBool(const char* key, bool value);
+ void AddEnum(const char* key, int value, EnumToStringFunction);
+ void AddCsv(const char* key, std::list<CStdString>& value);
+ void AddDate(const char* key, time_t value);
+ virtual void AddString(const char* key, CStdString& value) = 0;
+
+ void GetInt(const char* key, int& value, bool required = false);
+ void GetDouble(const char* key, double& value, bool required = false);
+ void GetBool(const char* key, bool& value, bool required = false);
+ void GetEnum(const char* key, int& value, StringToEnumFunction, bool required = false);
+ void GetCsv(const char* key, std::list<CStdString>& value, bool required = false);
+ void GetDate(const char* key, time_t& value, bool required = false);
+ virtual void GetString(const char* key, CStdString& value, bool required = false) = 0;
+
+protected:
+
+ Object* m_object;
+ bool m_deSerialize;
+};
+
+typedef boost::shared_ptr<Serializer> SerializerRef;
+
+/** Base class for all Key-Value pair based serializers.
+*/
+class DLL_IMPORT_EXPORT KeyValueSerializer : public Serializer
+{
+public:
+ KeyValueSerializer(Object* object) : Serializer(object), m_numParams(0){};
+
+ void ObjectValue(const char* key, Object& value, bool required = false);
+
+ void GetString(const char* key, CStdString& value, bool required = false);
+
+protected:
+ int m_numParams;
+ std::map<CStdString, CStdString> m_map;
+};
+
+#endif
+
diff --git a/orkbasecxx/serializers/SingleLineSerializer.cpp b/orkbasecxx/serializers/SingleLineSerializer.cpp
new file mode 100644
index 0000000..11b60d9
--- /dev/null
+++ b/orkbasecxx/serializers/SingleLineSerializer.cpp
@@ -0,0 +1,203 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "ace/OS_NS_ctype.h"
+#include "Utils.h"
+#include "SingleLineSerializer.h"
+
+
+void SingleLineSerializer::AddString(const char* key, CStdString& value)
+{
+ CStdString pair;
+ CStdString escapedValue;
+ EscapeSingleLine(value, escapedValue);
+ pair.Format("%s=%s ", key, (PCSTR)escapedValue);
+ m_output += pair;
+}
+
+CStdString SingleLineSerializer::Serialize()
+{
+ m_deSerialize = false; // Set Serialize mode
+ m_object->Define(this);
+ return m_output;
+}
+
+typedef enum {SingleLineStartState, SingleLineKeyState, SingleLineValueState, SingleLineErrorState} SingleLineState;
+
+void SingleLineSerializer::DeSerialize(CStdString& input)
+{
+ // read string and extract values into map
+ SingleLineState state = SingleLineStartState;
+ CStdString key;
+ CStdString value;
+ // #### Additionally, errorDescription should be converted to Exceptions
+ CStdString errorDescription;
+
+ input.Trim();
+
+ for(int i=0; i<input.length() && state!= SingleLineErrorState; i++)
+ {
+ TCHAR character = input[i];
+
+ switch(state)
+ {
+ case SingleLineStartState:
+ if(character == ' ')
+ {
+ ; // ignore spaces
+ }
+ else if ( ACE_OS::ace_isalnum(character) )
+ {
+ state = SingleLineKeyState;
+ key = character;
+ }
+ else
+ {
+ state = SingleLineErrorState;
+ errorDescription = "Cannot find key start, keys must be alphanum";
+ }
+ break;
+ case SingleLineKeyState:
+ if( ACE_OS::ace_isalnum(character) )
+ {
+ key += character;
+ }
+ else if (character == '=')
+ {
+ state = SingleLineValueState;
+ value.Empty();
+ }
+ else
+ {
+ state = SingleLineErrorState;
+ errorDescription = "Invalid key character, keys must be alphanum";
+ }
+ break;
+ case SingleLineValueState:
+ if( character == '=')
+ {
+ state = SingleLineErrorState;
+ errorDescription = "Value followed by = sign, value should always be followed by space sign";
+ }
+ else if (character == ' ')
+ {
+ state = SingleLineStartState;
+ }
+ else
+ {
+ value += character;
+ }
+ break;
+ default:
+ state = SingleLineErrorState;
+ errorDescription = "Non-existing state";
+ } // switch(state)
+
+ if ( (state == SingleLineStartState) || (i == (input.length()-1)) )
+ {
+ if (!key.IsEmpty())
+ {
+ // SingleLine unescape
+ CStdString unescapedValue;
+ UnEscapeSingleLine(value, unescapedValue);
+
+ // Add pair to key-value map
+ m_map.insert(std::make_pair(key, unescapedValue));
+ key.Empty();
+ value.Empty();
+ }
+ }
+ } // for(int i=0; i<input.length() && state!= SingleLineErrorState; i++)
+
+ m_deSerialize = true; // Set DeSerialize mode
+ m_object->Define(this);
+ m_object->Validate();
+}
+
+// Escape the space, colon and percent characters for serializing to Key-Value-Pair text
+void SingleLineSerializer::EscapeSingleLine(CStdString& in, CStdString& out)
+{
+ for(int i=0; i<in.length();i++)
+ {
+ TCHAR c = in[i];
+ if (c == ' ')
+ {
+ out+= "%s";
+ }
+ else if (c == ':')
+ {
+ out+= "%c";
+ }
+ else if (c == '%')
+ {
+ out+= "%p";
+ }
+ else
+ {
+ out+= c;
+ }
+ }
+}
+
+// Unescape the space, colon and percent characters for serializing to Key-Value-Pair text
+void SingleLineSerializer::UnEscapeSingleLine(CStdString& in, CStdString& out)
+{
+ int iin = 0;
+
+ while(iin<in.length())
+ {
+ if ( in[iin] == '%')
+ {
+ iin++;
+
+ switch (in[iin])
+ {
+ case 's':
+ out += ' ';
+ break;
+ case 'c':
+ out += ':';
+ break;
+ case 'p':
+ out += '%';
+ break;
+ }
+ }
+ else
+ {
+ out += in[iin];
+ }
+ iin++;
+ }
+}
+
+CStdString SingleLineSerializer::FindClass(CStdString& input)
+{
+ CStdString result;
+ int equalsPostion = input.Find('=');
+ if (equalsPostion != -1)
+ {
+ int spacePostion = input.Find(' ');
+ if (spacePostion > equalsPostion)
+ {
+ result = input.Mid(equalsPostion+1, spacePostion-equalsPostion-1);
+ }
+ else
+ {
+ result = input.Mid(equalsPostion+1, input.GetLength() - equalsPostion - 1);
+ }
+ }
+ result.ToLower();
+ return result;
+}
+
diff --git a/orkbasecxx/serializers/SingleLineSerializer.h b/orkbasecxx/serializers/SingleLineSerializer.h
new file mode 100644
index 0000000..62ada27
--- /dev/null
+++ b/orkbasecxx/serializers/SingleLineSerializer.h
@@ -0,0 +1,44 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __SINGLELINESERIALIZER_H__
+#define __SINGLELINESERIALIZER_H__
+
+#include "messages/Message.h"
+#include "serializers/Serializer.h"
+
+/** Serializer that generates and parses objects to and from a single line of text.
+ key-value pairs are separated by spaces.
+ key and values are separated by equal signs.
+ example: message=doit what=run
+*/
+class DLL_IMPORT_EXPORT SingleLineSerializer : public KeyValueSerializer
+{
+public:
+ SingleLineSerializer(Object* object) : KeyValueSerializer(object){};
+
+ void AddString(const char* key, CStdString& value);
+ CStdString Serialize();
+
+ void DeSerialize(CStdString& input);
+
+ void EscapeSingleLine(CStdString& in, CStdString& out);
+ void UnEscapeSingleLine(CStdString& in, CStdString& out);
+
+ static CStdString FindClass(CStdString& input);
+private:
+ CStdString m_output;
+};
+
+#endif
+
diff --git a/orkbasecxx/serializers/UrlSerializer.cpp b/orkbasecxx/serializers/UrlSerializer.cpp
new file mode 100644
index 0000000..1f33c18
--- /dev/null
+++ b/orkbasecxx/serializers/UrlSerializer.cpp
@@ -0,0 +1,161 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "ace/OS_NS_ctype.h"
+#include "Utils.h"
+#include "UrlSerializer.h"
+
+
+void UrlSerializer::AddString(const char* key, CStdString& value)
+{
+ CStdString pair;
+ CStdString escapedValue;
+ EscapeUrl(value, escapedValue);
+ pair.Format("%s=%s&", key, (PCSTR)escapedValue);
+ m_output += pair;
+}
+
+CStdString UrlSerializer::Serialize()
+{
+ m_deSerialize = false; // Set Serialize mode
+ m_object->Define(this);
+ return m_output;
+}
+
+typedef enum {UrlStartState, UrlKeyState, UrlValueState, UrlErrorState} UrlState;
+
+void UrlSerializer::DeSerialize(CStdString& input)
+{
+ // read string and extract values into map
+ UrlState state = UrlStartState;
+ CStdString key;
+ CStdString value;
+ CStdString errorDescription;
+
+ input.Trim();
+ input.ToLower();
+
+ for(int i=0; i<input.length() && state!= UrlErrorState; i++)
+ {
+ TCHAR character = input[i];
+
+ switch(state)
+ {
+ case UrlStartState:
+ if(character == '&')
+ {
+ ; // ignore ampersands
+ }
+ else if ( ACE_OS::ace_isalnum(character) )
+ {
+ state = UrlKeyState;
+ key = character;
+ }
+ else
+ {
+ state = UrlErrorState;
+ errorDescription = "Cannot find key start, keys must be alphanum";
+ }
+ break;
+ case UrlKeyState:
+ if( ACE_OS::ace_isalnum(character) )
+ {
+ key += character;
+ }
+ else if (character == '=')
+ {
+ state = UrlValueState;
+ value.Empty();
+ }
+ else
+ {
+ state = UrlErrorState;
+ errorDescription = "Invalid key character, keys must be alphanum";
+ }
+ break;
+ case UrlValueState:
+ if( character == '=')
+ {
+ state = UrlErrorState;
+ errorDescription = "Value followed by = sign, value should always be followed by space sign";
+ }
+ else if (character == '&')
+ {
+ state = UrlStartState;
+ }
+ else
+ {
+ value += character;
+ }
+ break;
+ default:
+ state = UrlErrorState;
+ errorDescription = "Non-existing state";
+ } // switch(state)
+
+ if ( (state == UrlStartState) || (i == (input.length()-1)) )
+ {
+ if (!key.IsEmpty())
+ {
+ // Url unescape
+ CStdString unescapedValue;
+ UnEscapeUrl(value, unescapedValue);
+
+ // Add pair to key-value map
+ m_map.insert(std::make_pair(key, unescapedValue));
+ key.Empty();
+ value.Empty();
+ }
+ }
+ } // for(int i=0; i<input.length() && state!= UrlErrorState; i++)
+
+ m_deSerialize = true; // Set DeSerialize mode
+ m_object->Define(this);
+ m_object->Validate();
+}
+
+// Escape the space, colon and percent characters for serializing to Key-Value-Pair text
+void UrlSerializer::EscapeUrl(CStdString& in, CStdString& out)
+{
+ //####### fixme, need unescaping
+ out = in;
+}
+
+// Unescape the space, colon and percent characters for serializing to Key-Value-Pair text
+void UrlSerializer::UnEscapeUrl(CStdString& in, CStdString& out)
+{
+ // ###### fixme, need escaping
+ out = in;
+}
+
+CStdString UrlSerializer::FindClass(CStdString& input)
+{
+ CStdString result;
+ int equalsPostion = input.Find('=');
+ if (equalsPostion != -1)
+ {
+ int ampersandPostion = input.Find('&');
+ if (ampersandPostion > equalsPostion)
+ {
+ // there is at least one parameter
+ result = input.Mid(equalsPostion+1, ampersandPostion-equalsPostion-1);
+ }
+ else
+ {
+ // there is no parameter
+ result = input.Mid(equalsPostion+1, input.GetLength() - equalsPostion - 1);
+ }
+ }
+ result.ToLower();
+ return result;
+} \ No newline at end of file
diff --git a/orkbasecxx/serializers/UrlSerializer.h b/orkbasecxx/serializers/UrlSerializer.h
new file mode 100644
index 0000000..5c2ce21
--- /dev/null
+++ b/orkbasecxx/serializers/UrlSerializer.h
@@ -0,0 +1,44 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __URLSERIALIZER_H__
+#define __URLSERIALIZER_H__
+
+#include "messages/Message.h"
+#include "serializers/Serializer.h"
+
+/** Serializer that generates and parses URLs from and to objects.
+ key-value pairs are separated by ampersands
+ keys and values are separated by equal signs
+ example: message=doit&what=run
+*/
+class DLL_IMPORT_EXPORT UrlSerializer : public KeyValueSerializer
+{
+public:
+ UrlSerializer(Object* object) : KeyValueSerializer(object){};
+
+ void AddString(const char* key, CStdString& value);
+ CStdString Serialize();
+
+ void DeSerialize(CStdString& input);
+
+ void EscapeUrl(CStdString& in, CStdString& out);
+ void UnEscapeUrl(CStdString& in, CStdString& out);
+
+ static CStdString FindClass(CStdString& input);
+private:
+ CStdString m_output;
+};
+
+#endif
+
diff --git a/orkbasecxx/serializers/XmlRpcSerializer.cpp b/orkbasecxx/serializers/XmlRpcSerializer.cpp
new file mode 100644
index 0000000..b9ffd88
--- /dev/null
+++ b/orkbasecxx/serializers/XmlRpcSerializer.cpp
@@ -0,0 +1,47 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+/*
+#include "XmlRpcSerializer.h"
+
+#define XMLRPC_METHOD_NAME "exec"
+
+
+void XmlRpcSerializer::AddInt(const char* key, int value)
+{
+ XmlRpcValue pair;
+ pair[0] = key;
+ pair[1] = value;
+ m_array[m_numParams++] = pair;
+}
+
+void XmlRpcSerializer::AddString(const char* key, CStdString& value)
+{
+ XmlRpcValue pair;
+ pair[0] = key;
+ pair[1] = (PCSTR)value;
+ m_array[m_numParams++] = pair;
+}
+
+bool XmlRpcSerializer::Invoke(CStdString& hostname, int tcpPort)
+{
+ m_object->Define(this);
+ m_hostname = hostname;
+ m_tcpPort = tcpPort;
+ m_params[0] = m_array;
+ XmlRpcClient client(m_hostname, m_tcpPort);
+ client.execute(XMLRPC_METHOD_NAME, m_params, m_ret);
+ client.close();
+ return m_ret.valid();
+}
+*/
diff --git a/orkbasecxx/serializers/XmlRpcSerializer.h b/orkbasecxx/serializers/XmlRpcSerializer.h
new file mode 100644
index 0000000..07bb59f
--- /dev/null
+++ b/orkbasecxx/serializers/XmlRpcSerializer.h
@@ -0,0 +1,45 @@
+/*
+ * Oreka -- A media capture and retrieval platform
+ *
+ * Copyright (C) 2005, orecx LLC
+ *
+ * http://www.orecx.com
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ * Please refer to http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __XMLRPCSERIALIZER_H__
+#define __XMLRPCSERIALIZER_H__
+/*
+#include "XmlRpc.h"
+#include "messages/Message.h"
+#include "serializers/Serializer.h"
+
+using namespace XmlRpc;
+*/
+/** Serializer that generates and parses XMLRPC parameters from and to objects.
+*/
+/*
+class DLL_IMPORT_EXPORT XmlRpcSerializer : public KeyValueSerializer
+{
+public:
+ //XmlRpcSerializer(Message* message, CStdString& hostname, int tcpPort);
+ XmlRpcSerializer(Object* object) : KeyValueSerializer(object){};
+
+ void AddInt(const char* key, int value);
+ void AddString(const char* key, CStdString& value);
+
+ bool Invoke(CStdString& hostname, int tcpPort);
+private:
+ CStdString m_hostname;
+ int m_tcpPort;
+ XmlRpcValue m_params;
+ XmlRpcValue m_array;
+ XmlRpcValue m_ret;
+};
+*/
+#endif
+