summaryrefslogtreecommitdiff
path: root/orkbasecxx/Utils.h
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/Utils.h
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/Utils.h')
-rw-r--r--orkbasecxx/Utils.h93
1 files changed, 93 insertions, 0 deletions
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
+