summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2006-03-03 15:23:24 +0000
committerHenri Herscher <henri@oreka.org>2006-03-03 15:23:24 +0000
commit229c98b195b283b9a5dc798480fb12f78eee06cd (patch)
treed17b41ccec986f2e2ba0ba54f0c9eedca3cbd81c
parent5c71b9542c24ff132c2c67c6ffe4a6a5bc43746c (diff)
Created Utils.cpp - Moved file utility functions from Utils.h to Utils.cpp - Created FileCanOpen()
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@191 09dcff7a-b715-0410-9601-b79a96267cd0
-rw-r--r--orkaudio/OrkAudio.cpp4
-rw-r--r--orkbasecxx/Utils.cpp50
-rw-r--r--orkbasecxx/Utils.h49
3 files changed, 69 insertions, 34 deletions
diff --git a/orkaudio/OrkAudio.cpp b/orkaudio/OrkAudio.cpp
index 14bf722..cfc04d6 100644
--- a/orkaudio/OrkAudio.cpp
+++ b/orkaudio/OrkAudio.cpp
@@ -208,8 +208,8 @@ int main(int argc, char* argv[])
{
// figure out service name
CStdString program(argv[0]);
- CStdString serviceNameWithExtension = BaseName(program);
- CStdString serviceName = StripFileExtension(serviceNameWithExtension);
+ CStdString serviceNameWithExtension = FileBaseName(program);
+ CStdString serviceName = FileStripExtension(serviceNameWithExtension);
if (serviceName.IsEmpty())
{
printf("Error: Could not determine service name.\n");
diff --git a/orkbasecxx/Utils.cpp b/orkbasecxx/Utils.cpp
new file mode 100644
index 0000000..c1ba665
--- /dev/null
+++ b/orkbasecxx/Utils.cpp
@@ -0,0 +1,50 @@
+#include "Utils.h"
+#include "ace/OS_NS_stdio.h"
+
+//========================================================
+// file related stuff
+
+CStdString FileBaseName(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);
+ }
+ else
+ {
+ result = path;
+ }
+ return result;
+}
+
+CStdString FileStripExtension(CStdString& filename)
+{
+ CStdString result;
+ int extensionPosition = filename.ReverseFind('.');
+ if (extensionPosition != -1)
+ {
+ result = filename.Left(extensionPosition);
+ }
+ else
+ {
+ result = filename;
+ }
+ return result;
+}
+
+bool FileCanOpen(CStdString& path)
+{
+ FILE* file = ACE_OS::fopen((PCSTR)path, "r");
+ if(file)
+ {
+ ACE_OS::fclose(file);
+ return true;
+ }
+ return false;
+}
diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h
index dcd22f2..7c14f28 100644
--- a/orkbasecxx/Utils.h
+++ b/orkbasecxx/Utils.h
@@ -25,6 +25,9 @@
#include "OrkBase.h"
+//============================================
+// String related stuff
+
inline CStdString IntToString(int integer)
{
CStdString ret;
@@ -59,42 +62,24 @@ inline double StringToDouble(CStdString& 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);
- }
- else
- {
- result = path;
- }
- return result;
-}
+//========================================================
+// file related stuff
-inline CStdString StripFileExtension(CStdString& filename)
-{
- CStdString result;
- int extensionPosition = filename.ReverseFind('.');
- if (extensionPosition != -1)
- {
- result = filename.Left(extensionPosition);
- }
- else
- {
- result = filename;
- }
- return result;
-}
+CStdString DLL_IMPORT_EXPORT FileBaseName(CStdString& path);
+CStdString DLL_IMPORT_EXPORT FileStripExtension(CStdString& filename);
+bool DLL_IMPORT_EXPORT FileCanOpen(CStdString& path);
+
+
+
+//=====================================================
+// threading related stuff
typedef ACE_Guard<ACE_Thread_Mutex> MutexSentinel;
+
+//=====================================================
+// Miscellanous stuff
+
/** A counter that generates a "counting" 3 character strings, i.e. aaa, aab, ..., zzz
that represents a number between 0 and 26^3-1 (wrapping counter)
and starts at a random location in this range.