Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A string utility class and a new Exception (used to throw out of band exception)
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 11 Jul 2008 15:14:45 +0000 (15:14 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 11 Jul 2008 15:14:45 +0000 (15:14 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5866 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/cxx/OutOfBoundsException.cxx [new file with mode: 0644]
src/cxx/OutOfBoundsException.hpp [new file with mode: 0644]
src/cxx/StringHelper.cxx [new file with mode: 0644]
src/cxx/StringHelper.hpp [new file with mode: 0644]

diff --git a/src/cxx/OutOfBoundsException.cxx b/src/cxx/OutOfBoundsException.cxx
new file mode 100644 (file)
index 0000000..3fb9412
--- /dev/null
@@ -0,0 +1,81 @@
+/*\r
+ * OutOfBoundsException.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* OutOfBoundsException member functions implementation.\r
+  */  \r
+\r
+#include <OutOfBoundsException.hpp>\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+                       OutOfBoundsException::OutOfBoundsException()\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Out of bounds") + 1, sizeof(char));\r
+                               strcpy(this->reason, "Out of bounds");\r
+                       }\r
+               \r
+               \r
+                       OutOfBoundsException::OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException)\r
+                       {\r
+                               const char* reason = rOutOfBoundsException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               strcpy(this->reason, reason);\r
+                               \r
+                       }\r
+               \r
+                       OutOfBoundsException::OutOfBoundsException(int pos)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Out of bounds ") + 21 + 1, sizeof(char));\r
+                               sprintf(this->reason, "Out of bounds %d", pos);\r
+                       }\r
+\r
+                       OutOfBoundsException::OutOfBoundsException(int pos1, int pos2)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Out of bounds ") + (2*21) + 1, sizeof(char));\r
+                               sprintf(this->reason, "Out of bounds %d : %d", pos1, pos2);\r
+                       }\r
+               \r
+               \r
+                       OutOfBoundsException::~OutOfBoundsException()\r
+                       {\r
+                               if(this->reason)\r
+                                       free(this->reason);\r
+                       }\r
+                               \r
+                       const char* OutOfBoundsException::toString(void) const\r
+                       {\r
+                               return (const char*)(this->reason);     \r
+                       }\r
+               \r
+               \r
+                       const OutOfBoundsException& OutOfBoundsException::operator = (const OutOfBoundsException& rOutOfBoundsException)\r
+                       {\r
+                               const char* reason = rOutOfBoundsException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               \r
+                               return *this;\r
+                       }\r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
diff --git a/src/cxx/OutOfBoundsException.hpp b/src/cxx/OutOfBoundsException.hpp
new file mode 100644 (file)
index 0000000..379c768
--- /dev/null
@@ -0,0 +1,71 @@
+/*\r
+ * OutOfBoundsException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
+#ifndef MSG_OUTOFBOUNDSEXCEPTION_HPP\r
+#define MSG_OUTOFBOUNDSEXCEPTION_HPP\r
+\r
+#ifndef __cplusplus\r
+       #error OutOfBoundsException.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <Exception.hpp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+               class SIMGRIDX_EXPORT OutOfBoundsException : public Exception\r
+               {\r
+                       public:\r
+                       \r
+                       // Default constructor.\r
+                               OutOfBoundsException();\r
+                       \r
+                       // Copy constructor.\r
+                               OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException);\r
+                       \r
+                       // This constructor takes the position in the range.\r
+                               OutOfBoundsException(int pos);\r
+\r
+                               OutOfBoundsException(int pos1, int pos2);\r
+                       \r
+                       // Destructor.\r
+                               virtual ~OutOfBoundsException();\r
+                               \r
+                       // Operations.\r
+                                       \r
+                                       // Returns the reason of the exception :\r
+                                       // the message "Out of bounds : `pos'"\r
+                                       const char* toString(void) const;\r
+                       \r
+                       // Operators.\r
+                               \r
+                               // Assignement.\r
+                               const OutOfBoundsException& operator = (const OutOfBoundsException& rOutOfBoundsException);\r
+                               \r
+                       private :\r
+                       \r
+                       // Attributes.\r
+                               \r
+                               // A buffer used to build the message returned by the methode toString().\r
+                               char* reason;\r
+               };\r
+               \r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_MSGEXCEPTION_HPP\r
+\r
diff --git a/src/cxx/StringHelper.cxx b/src/cxx/StringHelper.cxx
new file mode 100644 (file)
index 0000000..c64c6c1
--- /dev/null
@@ -0,0 +1,824 @@
+#include <StringHelper.hpp>\r
+\r
+#include <BadAllocException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <InvalidArgumentException.hpp>\r
+#include <OutOfBoundsException.hpp>\r
+\r
+#ifndef BUFF_MAX\r
+#define BUFF_MAX ((size_t)260)\r
+#endif // BUFF_MAX\r
+\r
+\r
+// namespace SimGrid::Msg\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+\r
+               #define DEFAULT_STRING_HELPER_CAPACITY ((int)128)\r
+               \r
+\r
+               void StringHelper::init(void)\r
+               {\r
+                       capacity = DEFAULT_STRING_HELPER_CAPACITY;\r
+\r
+                       if(!(content = (char*) calloc(capacity + 1, sizeof(char))))\r
+                               throw BadAllocException();\r
+\r
+                       len = 0;\r
+               }\r
+                               \r
+       // Default constructor\r
+               StringHelper::StringHelper()\r
+               {\r
+                       init();\r
+               }\r
+\r
+               StringHelper::StringHelper(char c)\r
+               {\r
+                       init();\r
+                       append(c);\r
+\r
+               }\r
+               \r
+               StringHelper::StringHelper(char c, int n)\r
+               {\r
+                       init();\r
+                       append(c, n);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const char* cstr)\r
+               {\r
+                       init();\r
+                       append(cstr);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const char* cstr, int n)\r
+               {\r
+                       init();\r
+                       append(cstr, n);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const char* cstr, int pos, int n)\r
+               {\r
+                       init();\r
+                       append(cstr, pos, n);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const string& rstr)\r
+               {\r
+                       init();\r
+                       append(rstr);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const string& rstr, int n)\r
+               {\r
+                       init();\r
+                       append(rstr, n);\r
+               }\r
+               \r
+               StringHelper::StringHelper(const string& rstr, int pos, int n)\r
+               {\r
+                       init();\r
+                       append(rstr, pos, n);\r
+               }\r
+               \r
+               StringHelper::StringHelper(short si)\r
+               {\r
+                       init();\r
+                       append(si);\r
+               }\r
+               \r
+               StringHelper::StringHelper(int i)\r
+               {\r
+                       init();\r
+                       append(i);\r
+               }\r
+               \r
+               StringHelper::StringHelper(long l)\r
+               {\r
+                       init();\r
+                       append(l);\r
+               }\r
+               \r
+               StringHelper::StringHelper(float f)\r
+               {\r
+                       init();\r
+                       append(f);\r
+               }\r
+               \r
+               StringHelper::StringHelper(double d)\r
+               {\r
+                       init();\r
+                       append(d);\r
+               }\r
+\r
+               StringHelper::StringHelper(double d, const char* format)\r
+               {\r
+                       char toAppend[BUFF_MAX + 1] = {0};\r
+                       \r
+                       sprintf(toAppend,format,d);\r
+\r
+                       init();\r
+\r
+                       append(toAppend);\r
+               }\r
+               \r
+               StringHelper::StringHelper(unsigned short usi)\r
+               {\r
+                       init();\r
+                       append(usi);\r
+               }\r
+               \r
+               StringHelper::StringHelper(unsigned int ui)\r
+               {\r
+                       init();\r
+                       append(ui);\r
+               }\r
+               \r
+               StringHelper::StringHelper(unsigned long ul)\r
+               {\r
+                       init();\r
+                       append(ul);\r
+               }\r
+       \r
+       // Copy constructor\r
+               StringHelper::StringHelper(const StringHelper& rStringHelper)\r
+               {\r
+                       if(this != &rStringHelper && rStringHelper.size())\r
+                       {\r
+                               clear();\r
+                               append(rStringHelper.cstr());\r
+                       }\r
+               }\r
+\r
+       // Destructor\r
+               StringHelper::~StringHelper()\r
+               {\r
+                       if(content)\r
+                               free(content);\r
+               }\r
+\r
+       // Operations\r
+\r
+               void StringHelper::clear(void)\r
+               {\r
+                       if(len)\r
+                               memset(content, 0, len);\r
+\r
+                       len = 0;\r
+               }\r
+\r
+               bool StringHelper::empty(void)\r
+               {\r
+                       return len == 0;\r
+               }\r
+       \r
+               StringHelper& StringHelper::append(unsigned char c)\r
+               {\r
+                       if(capacity < len + 1)\r
+                       {\r
+                               int new_capacity = (capacity << 1) ;\r
+\r
+                               if(!(content = (char*) realloc(content, new_capacity)))\r
+                                       throw BadAllocException();\r
+\r
+                               capacity = new_capacity;\r
+                       }\r
+                       \r
+\r
+                       content[len] = c;\r
+                       len++;\r
+\r
+                       content[len] = '\0';\r
+\r
+                       return *this;\r
+               }\r
+\r
+               StringHelper& StringHelper::append(unsigned char c, int n)\r
+               {\r
+                       if(n <=0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       char* toAppend = (char*) calloc(n + 1, sizeof(char));\r
+\r
+                       if(!toAppend)\r
+                               throw BadAllocException();\r
+\r
+                       memset(toAppend, c, n); \r
+\r
+                       append(toAppend);\r
+\r
+                       free(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+\r
+       \r
+               StringHelper& StringHelper::append(char c)\r
+               {\r
+                       if(capacity < len + 1)\r
+                       {\r
+                               int new_capacity = (capacity << 1) ;\r
+\r
+                               if(!(content = (char*) realloc(content, new_capacity)))\r
+                                       throw BadAllocException();\r
+\r
+                               capacity = new_capacity;\r
+                       }\r
+                       \r
+\r
+                       content[len] = c;\r
+                       len++;\r
+\r
+                       content[len] = '\0';\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(char c, int n)\r
+               {\r
+                       if(n <=0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       char* toAppend = (char*) calloc(n + 1, sizeof(char));\r
+\r
+                       if(!toAppend)\r
+                               throw BadAllocException();\r
+\r
+                       memset(toAppend, c, n); \r
+\r
+                       append(toAppend);\r
+\r
+                       free(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const char* cstr)\r
+               {\r
+                       if(!cstr)\r
+                               throw NullPointerException("cstr");\r
+                       \r
+                       int l =  (int) strlen(cstr);\r
+\r
+                       if(capacity < len + l)\r
+                       {\r
+                               int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1;\r
+\r
+                               if(!(content = (char*) realloc(content, new_capacity)))\r
+                                       throw BadAllocException();\r
+\r
+                               strcat(content, cstr);\r
+\r
+                               capacity = new_capacity;\r
+                       }\r
+                       else\r
+                       {\r
+                               strcat(content, cstr);\r
+                       }\r
+\r
+                       len += l;\r
+                       content[len] = '\0';\r
+\r
+                       return *this;\r
+                       \r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const char* cstr, int n)\r
+               {\r
+                       if(!cstr)\r
+                               throw NullPointerException("cstr");\r
+\r
+                       if(n <= 0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       \r
+                       int l =  ((int) strlen(cstr)) * n;\r
+\r
+                       if(capacity < len + l)\r
+                       {\r
+                               int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1;\r
+\r
+                               if(!(content = (char*) realloc(content, new_capacity)))\r
+                                       throw BadAllocException();\r
+                               \r
+                               for(int i = 0; i < n; i++)\r
+                                       strcat(content, cstr);\r
+\r
+                               capacity = new_capacity;\r
+                       }\r
+                       else\r
+                       {\r
+                               for(int i = 0; i < n; i++)\r
+                                       strcat(content, cstr);\r
+                       }\r
+\r
+                       len += l;\r
+                       content[len] = '\0';\r
+\r
+                       return *this;\r
+\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const char* cstr, int pos, int n)\r
+               {\r
+                       if(!cstr)\r
+                               throw NullPointerException("cstr");\r
+\r
+                       if(n <= 0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       if(pos < 0 || pos >= (int)strlen(cstr) )\r
+                               throw OutOfBoundsException(pos);\r
+\r
+                       if(pos + n >= (int)strlen(cstr))\r
+                               throw OutOfBoundsException(pos, n);\r
+\r
+\r
+                       char* toAppend = (char*) calloc(n + 1, sizeof(char));\r
+                       \r
+                       strncpy(toAppend, cstr + pos, n);\r
+\r
+                       append(toAppend);\r
+\r
+                       free(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const string& rstr)\r
+               {\r
+                       append(rstr.c_str());\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const string& rstr, int n)\r
+               {\r
+                       if(rstr.empty())\r
+                               throw NullPointerException("rstr");\r
+\r
+                       if(n <= 0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       \r
+                       int l =  ((int) rstr.size()) * n;\r
+\r
+                       if(capacity < len + l)\r
+                       {\r
+                               int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1;\r
+\r
+                               if(!(content = (char*) realloc(content, new_capacity)))\r
+                                       throw BadAllocException();\r
+                               \r
+                               for(int i = 0; i < n; i++)\r
+                                       strcat(content, rstr.c_str());\r
+\r
+                               capacity = new_capacity;\r
+                       }\r
+                       else\r
+                       {\r
+                               for(int i = 0; i < n; i++)\r
+                                       strcat(content, rstr.c_str());\r
+                       }\r
+\r
+                       len += l;\r
+                       content[len] = '\0';\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(const string& rstr, int pos, int n)\r
+               {\r
+                       if(rstr.empty())\r
+                               throw InvalidArgumentException("rstr");\r
+\r
+                       if(n <= 0)\r
+                               throw InvalidArgumentException("n");\r
+\r
+                       if(pos < 0 || pos >= (int) rstr.size() )\r
+                               throw OutOfBoundsException(pos);\r
+\r
+                       if(pos + n >=  (int) rstr.size())\r
+                               throw OutOfBoundsException(pos, n);\r
+\r
+\r
+                       char* toAppend = (char*) calloc(n + 1, sizeof(char));\r
+                       \r
+                       strncpy(toAppend, rstr.c_str() + pos, n);\r
+\r
+                       append(toAppend);\r
+\r
+                       free(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(short si)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%hd",si);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(int i)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%d",i);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(long l)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%ld",l);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(float f)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%f",f);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(double d)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%lf",d);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+\r
+               StringHelper& StringHelper::append(double d, const char* format)\r
+               {\r
+                       char toAppend[BUFF_MAX + 1] = {0};\r
+\r
+                       sprintf(toAppend, format, d);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(unsigned short usi)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%hu",usi);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(unsigned int ui)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%u",ui);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::append(unsigned long ul)\r
+               {\r
+                       char toAppend[26] = {0};\r
+\r
+                       sprintf(toAppend, "%lu",ul);\r
+\r
+                       append(toAppend);\r
+\r
+                       return *this;\r
+               }\r
+                       \r
+               const char& StringHelper::at(int pos) const\r
+               {\r
+                       if(pos < 0 || pos >= len)\r
+                               throw OutOfBoundsException(pos);\r
+                       \r
+                       return content[pos];\r
+               }\r
+               \r
+               char& StringHelper::at(int pos)\r
+               {\r
+                       if(pos < 0 || pos >= len)\r
+                               throw OutOfBoundsException(pos);\r
+                       \r
+                       return content[pos];\r
+               }\r
+               \r
+               const char* StringHelper::cstr(void) const\r
+               {\r
+                       return (const char*)content;\r
+               }\r
+               \r
+               string& StringHelper::toString(void)\r
+               {\r
+                       string* s = new string();\r
+                       s->append(content);\r
+                       return *s;\r
+               }\r
+               \r
+               int StringHelper::size(void) const\r
+               {\r
+                       return len;\r
+               }\r
+               \r
+       //  Operators\r
+               \r
+               // Assignement\r
+               StringHelper& StringHelper::operator = (const StringHelper& rStringHelper)\r
+               {\r
+\r
+                       if(this !=&rStringHelper && rStringHelper.size())\r
+                       {\r
+                               clear();\r
+                               append(rStringHelper.cstr());\r
+                       }\r
+\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (const char* cstr)\r
+               {\r
+                       clear();\r
+                       append(cstr);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (const string& str)\r
+               {\r
+                       clear();\r
+                       append(str);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (short n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (int n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (long n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (float n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (double n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (unsigned short n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (unsigned int n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator = (unsigned long n)\r
+               {\r
+                       clear();\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               char& StringHelper::operator[](int pos)\r
+               {\r
+                       if(pos < 0 || pos >= len)\r
+                               throw OutOfBoundsException(pos);\r
+                       \r
+                       return content[pos];    \r
+               }\r
+               \r
+               char StringHelper::operator[](int pos) const\r
+               {\r
+                       if(pos < 0 || pos >= len)\r
+                               throw OutOfBoundsException(pos);\r
+                       \r
+                       return content[pos];\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (short n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (int n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (long n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (float n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (double n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (unsigned short n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (unsigned int n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (unsigned long n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (const StringHelper& rStringHelper)\r
+               {\r
+                       append(rStringHelper.content);\r
+                       return *this;\r
+               }\r
+\r
+               StringHelper& StringHelper::operator += (const string& rstr)\r
+               {\r
+                       append(rstr.c_str());\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (const char* cstr)\r
+               {\r
+                       append(cstr);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator += (char c)\r
+               {\r
+                       append(c);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (short n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (int n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (long n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (float n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (double n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (unsigned short n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (unsigned int n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (unsigned long n)\r
+               {\r
+                       append(n);\r
+                       return *this;\r
+               }\r
+               \r
+               \r
+               StringHelper& StringHelper::operator + (const StringHelper& rStringHelper)\r
+               {\r
+                       append(rStringHelper.content);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (const string& rstr)\r
+               {\r
+                       append(rstr.c_str());\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (const char* cstr)\r
+               {\r
+                       append(cstr);\r
+                       return *this;\r
+               }\r
+               \r
+               StringHelper& StringHelper::operator + (char c)\r
+               {\r
+                       append(c);\r
+                       return *this;\r
+               }\r
+\r
+               StringHelper::operator char *()\r
+               {\r
+                       return content;\r
+               }\r
+\r
+               StringHelper::operator const char *()\r
+               {\r
+                       return content;\r
+               }\r
+\r
+               ostream& operator<<(ostream& stream, const StringHelper& s)\r
+               {\r
+                       stream << s.cstr();\r
+                       return stream;\r
+               }\r
+\r
+               istream& operator<<(istream& stream, StringHelper& s)\r
+               {\r
+                       char buff[256] = {0};\r
+\r
+                       stream >> buff;\r
+\r
+                       s.append(buff);\r
+\r
+                       return stream;\r
+               }\r
+                               \r
+       } // namespace Msg\r
+} // namespace SimGrid
\ No newline at end of file
diff --git a/src/cxx/StringHelper.hpp b/src/cxx/StringHelper.hpp
new file mode 100644 (file)
index 0000000..a1675d3
--- /dev/null
@@ -0,0 +1,245 @@
+/*\r
+ * StringHelper.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
+#ifndef STRING_HELPER_HPP\r
+#define STRING_HELPER_HPP\r
+\r
+ #ifndef __cplusplus\r
+       #error StringHelper.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+#include<iostream>\r
+using std::ostream;\r
+using std::istream;\r
+\r
+#include <Config.hpp>\r
+\r
+// namespace SimGrid::Msg\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               class SIMGRIDX_EXPORT StringHelper\r
+               {\r
+                       public:\r
+                               \r
+                               // Default constructor\r
+                                       StringHelper();\r
+\r
+                                       StringHelper(unsigned char c);\r
+                               \r
+                                       StringHelper(unsigned char c, int n);\r
+                               \r
+                                       StringHelper(char c);\r
+                               \r
+                                       StringHelper(char c, int n);\r
+                               \r
+                                       StringHelper(const char* cstr);\r
+                                       \r
+                                       StringHelper(const char* cstr, int n);\r
+                                       \r
+                                       StringHelper(const char* cstr, int pos, int n);\r
+                                       \r
+                                       StringHelper(const string& rstr);\r
+                                       \r
+                                       StringHelper(const string& rstr, int n);\r
+                                       \r
+                                       StringHelper(const string& rstr, int pos, int n);\r
+                                       \r
+                                       StringHelper(short si);\r
+                                       \r
+                                       StringHelper(int i);\r
+                                       \r
+                                       StringHelper(long l);\r
+                                       \r
+                                       StringHelper(float f);\r
+                                       \r
+                                       StringHelper(double d);\r
+\r
+                                       StringHelper(double d, const char* format);\r
+                                       \r
+                                       StringHelper(unsigned short usi);\r
+                                       \r
+                                       StringHelper(unsigned int ui);\r
+                                       \r
+                                       StringHelper(unsigned long ul);\r
+                               \r
+                               // Copy constructor\r
+                                       StringHelper(const StringHelper& rStringHelper);\r
+                               \r
+                               // Destructor\r
+                                       ~StringHelper();\r
+\r
+                               // Operations\r
+                               \r
+                                       StringHelper& append(unsigned char c);\r
+                               \r
+                                       StringHelper& append(unsigned char c, int n);\r
+                               \r
+                                       StringHelper& append(char c);\r
+                               \r
+                                       StringHelper& append(char c, int n);\r
+                               \r
+                                       StringHelper& append(const char* cstr);\r
+                                       \r
+                                       StringHelper& append(const char* cstr, int n);\r
+                                       \r
+                                       StringHelper& append(const char* cstr, int pos, int n);\r
+                                       \r
+                                       StringHelper& append(const string& rstr);\r
+                                       \r
+                                       StringHelper& append(const string& rstr, int n);\r
+                                       \r
+                                       StringHelper& append(const string& rstr, int pos, int n);\r
+                                       \r
+                                       StringHelper& append(short si);\r
+                                       \r
+                                       StringHelper& append(int i);\r
+                                       \r
+                                       StringHelper& append(long l);\r
+                                       \r
+                                       StringHelper& append(float f);\r
+                                       \r
+                                       StringHelper& append(double d);\r
+                                       \r
+                                       StringHelper& append(double d, const char* format);\r
+                                       \r
+                                       StringHelper& append(unsigned short usi);\r
+                                       \r
+                                       StringHelper& append(unsigned int ui);\r
+                                       \r
+                                       StringHelper& append(unsigned long ul);\r
+                                       \r
+                               const char& at(int pos) const;\r
+                               \r
+                               char& at(int pos);\r
+                                       \r
+                                       const char* cstr(void) const;\r
+                                       \r
+                                       string& toString(void);\r
+                                       \r
+                                       int size(void) const;\r
+\r
+                                       void clear(void);\r
+\r
+                                       bool empty(void);\r
+                                       \r
+                               //  Operators\r
+                                       \r
+                                       // Assignement\r
+                                       StringHelper& operator = (const StringHelper& rStringHelper);\r
+                                       \r
+                                       StringHelper& operator = (const char* cstr);\r
+                                       \r
+                                       StringHelper& operator = (const string& str);\r
+                                       \r
+                                       StringHelper& operator = (short n);\r
+                                       \r
+                                       StringHelper& operator = (int n);\r
+                                       \r
+                                       StringHelper& operator = (long n);\r
+                                       \r
+                                       StringHelper& operator = (float n);\r
+                                       \r
+                                       StringHelper& operator = (double n);\r
+                                       \r
+                                       StringHelper& operator = (unsigned short n);\r
+                                       \r
+                                       StringHelper& operator = (unsigned int n);\r
+                                       \r
+                                       StringHelper& operator = (unsigned long n);\r
+                                       \r
+                                       char& operator[](int pos);\r
+                                       \r
+                                       char operator[](int pos) const;\r
+                                       \r
+                                       StringHelper& operator += (short n);\r
+                                       \r
+                                       StringHelper& operator += (int n);\r
+                                       \r
+                                       StringHelper& operator += (long n);\r
+                                       \r
+                                       StringHelper& operator += (float n);\r
+                                       \r
+                                       StringHelper& operator += (double n);\r
+                                       \r
+                                       StringHelper& operator += (unsigned short n);\r
+                                       \r
+                                       StringHelper& operator += (unsigned int n);\r
+                                       \r
+                                       StringHelper& operator += (unsigned long n);\r
+                                       \r
+                                       StringHelper& operator += (const StringHelper& rStringHelper);\r
+                                       \r
+                                       StringHelper& operator += (const string& rstr);\r
+                                       \r
+                               StringHelper& operator += (const char* cstr);\r
+                               \r
+                               StringHelper& operator += (char c);\r
+                               \r
+                                       StringHelper& operator + (short n);\r
+                                       \r
+                                       StringHelper& operator + (int n);\r
+                                       \r
+                                       StringHelper& operator + (long n);\r
+                                       \r
+                                       StringHelper& operator + (float n);\r
+                                       \r
+                                       StringHelper& operator + (double n);\r
+                                       \r
+                                       StringHelper& operator + (unsigned short n);\r
+                                       \r
+                                       StringHelper& operator + (unsigned int n);\r
+                                       \r
+                                       StringHelper& operator + (unsigned long n);\r
+                                       \r
+                                       StringHelper& operator + (const StringHelper& rStringHelper);\r
+                                       \r
+                                       StringHelper& operator + (const string& rstr);\r
+                                       \r
+                               StringHelper& operator + (const char* cstr);\r
+                               \r
+                               StringHelper& operator + (char c);\r
+\r
+                                       operator char *();\r
+\r
+                                       operator const char *();\r
+\r
+                                       friend SIMGRIDX_EXPORT ostream& operator<<(ostream& stream, const StringHelper& s);\r
+\r
+                                       friend SIMGRIDX_EXPORT istream& operator<<(istream& stream, StringHelper& s);\r
+                               \r
+                               private:\r
+\r
+                                       // Methods\r
+                                       void init(void);\r
+                                       \r
+                                       // Attributes\r
+                                       \r
+                                       char* content;\r
+                                       int capacity;\r
+                                       int len;\r
+               };\r
+               \r
+               typedef class StringHelper* StringHelperPtr;\r
+\r
+               #define TEXT_(___x)     StringHelper((___x))\r
+\r
+\r
+       } // namespace Msg\r
+} // namespace SimGrid\r
+\r
+\r
+#endif // !STRING_HELPER_HPP
\ No newline at end of file