summaryrefslogtreecommitdiff
path: root/src/dpl/core/include/cchecker
diff options
context:
space:
mode:
Diffstat (limited to 'src/dpl/core/include/cchecker')
-rw-r--r--src/dpl/core/include/cchecker/dpl/assert.h14
-rw-r--r--src/dpl/core/include/cchecker/dpl/colors.h74
-rw-r--r--src/dpl/core/include/cchecker/dpl/exception.h617
-rw-r--r--src/dpl/core/include/cchecker/dpl/noncopyable.h15
-rw-r--r--src/dpl/core/include/cchecker/dpl/optional.h274
-rw-r--r--src/dpl/core/include/cchecker/dpl/scoped_array.h51
-rw-r--r--src/dpl/core/include/cchecker/dpl/scoped_free.h32
-rw-r--r--src/dpl/core/include/cchecker/dpl/scoped_resource.h77
-rw-r--r--src/dpl/core/include/cchecker/dpl/serialization.h849
-rw-r--r--src/dpl/core/include/cchecker/dpl/string.h123
10 files changed, 1059 insertions, 1067 deletions
diff --git a/src/dpl/core/include/cchecker/dpl/assert.h b/src/dpl/core/include/cchecker/dpl/assert.h
index 03dd7d0..1bb918e 100644
--- a/src/dpl/core/include/cchecker/dpl/assert.h
+++ b/src/dpl/core/include/cchecker/dpl/assert.h
@@ -29,15 +29,15 @@ namespace CCHECKER {
// Do not call directly
// Always use Assert macro
CCHECKER_NORETURN void AssertProc(const char *condition,
- const char *file,
- int line,
- const char *function);
+ const char *file,
+ int line,
+ const char *function);
} // namespace CCHECKER
#define Assert(Condition) do { if (!(Condition)) { CCHECKER::AssertProc(#Condition, \
- __FILE__, \
- __LINE__, \
- __FUNCTION__); \
- } } while (0)
+ __FILE__, \
+ __LINE__, \
+ __FUNCTION__); \
+ } } while (0)
#endif // CCHECKER_ASSERT_H
diff --git a/src/dpl/core/include/cchecker/dpl/colors.h b/src/dpl/core/include/cchecker/dpl/colors.h
index d652f5b..b1cf04a 100644
--- a/src/dpl/core/include/cchecker/dpl/colors.h
+++ b/src/dpl/core/include/cchecker/dpl/colors.h
@@ -27,46 +27,46 @@
namespace CCHECKER {
namespace Colors {
namespace Text {
-extern const char* BOLD_GREEN_BEGIN;
-extern const char* BOLD_GREEN_END;
-extern const char* PURPLE_BEGIN;
-extern const char* PURPLE_END;
-extern const char* RED_BEGIN;
-extern const char* RED_END;
-extern const char* GREEN_BEGIN;
-extern const char* GREEN_END;
-extern const char* CYAN_BEGIN;
-extern const char* CYAN_END;
-extern const char* BOLD_RED_BEGIN;
-extern const char* BOLD_RED_END;
-extern const char* BOLD_YELLOW_BEGIN;
-extern const char* BOLD_YELLOW_END;
-extern const char* BOLD_GOLD_BEGIN;
-extern const char* BOLD_GOLD_END;
-extern const char* BOLD_WHITE_BEGIN;
-extern const char* BOLD_WHITE_END;
-extern const char* COLOR_END;
+extern const char *BOLD_GREEN_BEGIN;
+extern const char *BOLD_GREEN_END;
+extern const char *PURPLE_BEGIN;
+extern const char *PURPLE_END;
+extern const char *RED_BEGIN;
+extern const char *RED_END;
+extern const char *GREEN_BEGIN;
+extern const char *GREEN_END;
+extern const char *CYAN_BEGIN;
+extern const char *CYAN_END;
+extern const char *BOLD_RED_BEGIN;
+extern const char *BOLD_RED_END;
+extern const char *BOLD_YELLOW_BEGIN;
+extern const char *BOLD_YELLOW_END;
+extern const char *BOLD_GOLD_BEGIN;
+extern const char *BOLD_GOLD_END;
+extern const char *BOLD_WHITE_BEGIN;
+extern const char *BOLD_WHITE_END;
+extern const char *COLOR_END;
} //namespace Text
namespace Html {
-extern const char* BOLD_GREEN_BEGIN;
-extern const char* BOLD_GREEN_END;
-extern const char* PURPLE_BEGIN;
-extern const char* PURPLE_END;
-extern const char* RED_BEGIN;
-extern const char* RED_END;
-extern const char* GREEN_BEGIN;
-extern const char* GREEN_END;
-extern const char* CYAN_BEGIN;
-extern const char* CYAN_END;
-extern const char* BOLD_RED_BEGIN;
-extern const char* BOLD_RED_END;
-extern const char* BOLD_YELLOW_BEGIN;
-extern const char* BOLD_YELLOW_END;
-extern const char* BOLD_GOLD_BEGIN;
-extern const char* BOLD_GOLD_END;
-extern const char* BOLD_WHITE_BEGIN;
-extern const char* BOLD_WHITE_END;
+extern const char *BOLD_GREEN_BEGIN;
+extern const char *BOLD_GREEN_END;
+extern const char *PURPLE_BEGIN;
+extern const char *PURPLE_END;
+extern const char *RED_BEGIN;
+extern const char *RED_END;
+extern const char *GREEN_BEGIN;
+extern const char *GREEN_END;
+extern const char *CYAN_BEGIN;
+extern const char *CYAN_END;
+extern const char *BOLD_RED_BEGIN;
+extern const char *BOLD_RED_END;
+extern const char *BOLD_YELLOW_BEGIN;
+extern const char *BOLD_YELLOW_END;
+extern const char *BOLD_GOLD_BEGIN;
+extern const char *BOLD_GOLD_END;
+extern const char *BOLD_WHITE_BEGIN;
+extern const char *BOLD_WHITE_END;
} //namespace Html
} //namespace Colors
} //namespace CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/exception.h b/src/dpl/core/include/cchecker/dpl/exception.h
index f7b9afc..a23e4ef 100644
--- a/src/dpl/core/include/cchecker/dpl/exception.h
+++ b/src/dpl/core/include/cchecker/dpl/exception.h
@@ -32,340 +32,331 @@
namespace CCHECKER {
void LogUnhandledException(const std::string &str);
void LogUnhandledException(const std::string &str,
- const char *filename,
- int line,
- const char *function);
+ const char *filename,
+ int line,
+ const char *function);
}
namespace CCHECKER {
-class Exception
-{
- private:
- static unsigned int m_exceptionCount;
- static Exception* m_lastException;
- static void (*m_terminateHandler)();
-
- static void AddRef(Exception* exception)
- {
- if (!m_exceptionCount) {
- m_terminateHandler = std::set_terminate(&TerminateHandler);
- }
-
- ++m_exceptionCount;
- m_lastException = exception;
- }
-
- static void UnRef(Exception* e)
- {
- if (m_lastException == e) {
- m_lastException = NULL;
- }
-
- --m_exceptionCount;
-
- if (!m_exceptionCount) {
- std::set_terminate(m_terminateHandler);
- m_terminateHandler = NULL;
- }
- }
-
- static void TerminateHandler()
- {
- if (m_lastException != NULL) {
- DisplayKnownException(*m_lastException);
- abort();
- } else {
- DisplayUnknownException();
- abort();
- }
- }
-
- Exception *m_reason;
- std::string m_path;
- std::string m_function;
- int m_line;
-
- protected:
- std::string m_message;
- std::string m_className;
-
- public:
- static std::string KnownExceptionToString(const Exception &e)
- {
- std::ostringstream message;
- message <<
- "\033[1;5;31m\n=== Unhandled CCHECKER exception occurred ===\033[m\n\n";
- message << "\033[1;33mException trace:\033[m\n\n";
- message << e.DumpToString();
- message << "\033[1;31m\n=== Will now abort ===\033[m\n";
-
- return message.str();
- }
-
- static std::string UnknownExceptionToString()
- {
- std::ostringstream message;
- message <<
- "\033[1;5;31m\n=== Unhandled non-CCHECKER exception occurred ===\033[m\n\n";
- message << "\033[1;31m\n=== Will now abort ===\033[m\n";
-
- return message.str();
- }
-
- static void DisplayKnownException(const Exception& e)
- {
- LogUnhandledException(KnownExceptionToString(e).c_str());
- }
-
- static void DisplayUnknownException()
- {
- LogUnhandledException(UnknownExceptionToString().c_str());
- }
-
- Exception(const Exception &other)
- {
- // Deep copy
- if (other.m_reason != NULL) {
- m_reason = new Exception(*other.m_reason);
- } else {
- m_reason = NULL;
- }
-
- m_message = other.m_message;
- m_path = other.m_path;
- m_function = other.m_function;
- m_line = other.m_line;
-
- m_className = other.m_className;
-
- AddRef(this);
- }
-
- const Exception &operator =(const Exception &other)
- {
- if (this == &other) {
- return *this;
- }
-
- // Deep copy
- if (other.m_reason != NULL) {
- m_reason = new Exception(*other.m_reason);
- } else {
- m_reason = NULL;
- }
-
- m_message = other.m_message;
- m_path = other.m_path;
- m_function = other.m_function;
- m_line = other.m_line;
-
- m_className = other.m_className;
-
- AddRef(this);
-
- return *this;
- }
-
- Exception(const char *path,
- const char *function,
- int line,
- const std::string &message) :
- m_reason(NULL),
- m_path(path),
- m_function(function),
- m_line(line),
- m_message(message)
- {
- AddRef(this);
- }
-
- Exception(const char *path,
- const char *function,
- int line,
- const Exception &reason,
- const std::string &message) :
- m_reason(new Exception(reason)),
- m_path(path),
- m_function(function),
- m_line(line),
- m_message(message)
- {
- AddRef(this);
- }
-
- virtual ~Exception() throw()
- {
- if (m_reason != NULL) {
- delete m_reason;
- m_reason = NULL;
- }
-
- UnRef(this);
- }
-
- void Dump() const
- {
- // Show reason first
- if (m_reason != NULL) {
- m_reason->Dump();
- }
-
- // Afterward, dump exception
- const char *file = strchr(m_path.c_str(), '/');
-
- if (file == NULL) {
- file = m_path.c_str();
- } else {
- ++file;
- }
-
- printf("\033[0;36m[%s:%i]\033[m %s() \033[4;35m%s\033[m: %s\033[m\n",
- file, m_line,
- m_function.c_str(),
- m_className.c_str(),
- m_message.empty() ? "<EMPTY>" : m_message.c_str());
- }
-
- std::string DumpToString() const
- {
- std::string ret;
- if (m_reason != NULL) {
- ret = m_reason->DumpToString();
- }
-
- const char *file = strchr(m_path.c_str(), '/');
-
- if (file == NULL) {
- file = m_path.c_str();
- } else {
- ++file;
- }
-
- char buf[1024];
- snprintf(buf,
- sizeof(buf),
- "\033[0;36m[%s:%i]\033[m %s() \033[4;35m%s\033[m: %s\033[m\n",
- file,
- m_line,
- m_function.c_str(),
- m_className.c_str(),
- m_message.empty() ? "<EMPTY>" : m_message.c_str());
-
- buf[sizeof(buf) - 1] = '\n';
- ret += buf;
-
- return ret;
- }
-
- Exception *GetReason() const
- {
- return m_reason;
- }
-
- std::string GetPath() const
- {
- return m_path;
- }
-
- std::string GetFunction() const
- {
- return m_function;
- }
-
- int GetLine() const
- {
- return m_line;
- }
-
- std::string GetMessage() const
- {
- return m_message;
- }
-
- std::string GetClassName() const
- {
- return m_className;
- }
+class Exception {
+private:
+ static unsigned int m_exceptionCount;
+ static Exception *m_lastException;
+ static void (*m_terminateHandler)();
+
+ static void AddRef(Exception *exception)
+ {
+ if (!m_exceptionCount) {
+ m_terminateHandler = std::set_terminate(&TerminateHandler);
+ }
+
+ ++m_exceptionCount;
+ m_lastException = exception;
+ }
+
+ static void UnRef(Exception *e)
+ {
+ if (m_lastException == e) {
+ m_lastException = NULL;
+ }
+
+ --m_exceptionCount;
+
+ if (!m_exceptionCount) {
+ std::set_terminate(m_terminateHandler);
+ m_terminateHandler = NULL;
+ }
+ }
+
+ static void TerminateHandler()
+ {
+ if (m_lastException != NULL) {
+ DisplayKnownException(*m_lastException);
+ abort();
+ } else {
+ DisplayUnknownException();
+ abort();
+ }
+ }
+
+ Exception *m_reason;
+ std::string m_path;
+ std::string m_function;
+ int m_line;
+
+protected:
+ std::string m_message;
+ std::string m_className;
+
+public:
+ static std::string KnownExceptionToString(const Exception &e)
+ {
+ std::ostringstream message;
+ message <<
+ "\033[1;5;31m\n=== Unhandled CCHECKER exception occurred ===\033[m\n\n";
+ message << "\033[1;33mException trace:\033[m\n\n";
+ message << e.DumpToString();
+ message << "\033[1;31m\n=== Will now abort ===\033[m\n";
+ return message.str();
+ }
+
+ static std::string UnknownExceptionToString()
+ {
+ std::ostringstream message;
+ message <<
+ "\033[1;5;31m\n=== Unhandled non-CCHECKER exception occurred ===\033[m\n\n";
+ message << "\033[1;31m\n=== Will now abort ===\033[m\n";
+ return message.str();
+ }
+
+ static void DisplayKnownException(const Exception &e)
+ {
+ LogUnhandledException(KnownExceptionToString(e).c_str());
+ }
+
+ static void DisplayUnknownException()
+ {
+ LogUnhandledException(UnknownExceptionToString().c_str());
+ }
+
+ Exception(const Exception &other)
+ {
+ // Deep copy
+ if (other.m_reason != NULL) {
+ m_reason = new Exception(*other.m_reason);
+ } else {
+ m_reason = NULL;
+ }
+
+ m_message = other.m_message;
+ m_path = other.m_path;
+ m_function = other.m_function;
+ m_line = other.m_line;
+ m_className = other.m_className;
+ AddRef(this);
+ }
+
+ const Exception &operator =(const Exception &other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+
+ // Deep copy
+ if (other.m_reason != NULL) {
+ m_reason = new Exception(*other.m_reason);
+ } else {
+ m_reason = NULL;
+ }
+
+ m_message = other.m_message;
+ m_path = other.m_path;
+ m_function = other.m_function;
+ m_line = other.m_line;
+ m_className = other.m_className;
+ AddRef(this);
+ return *this;
+ }
+
+ Exception(const char *path,
+ const char *function,
+ int line,
+ const std::string &message) :
+ m_reason(NULL),
+ m_path(path),
+ m_function(function),
+ m_line(line),
+ m_message(message)
+ {
+ AddRef(this);
+ }
+
+ Exception(const char *path,
+ const char *function,
+ int line,
+ const Exception &reason,
+ const std::string &message) :
+ m_reason(new Exception(reason)),
+ m_path(path),
+ m_function(function),
+ m_line(line),
+ m_message(message)
+ {
+ AddRef(this);
+ }
+
+ virtual ~Exception() throw()
+ {
+ if (m_reason != NULL) {
+ delete m_reason;
+ m_reason = NULL;
+ }
+
+ UnRef(this);
+ }
+
+ void Dump() const
+ {
+ // Show reason first
+ if (m_reason != NULL) {
+ m_reason->Dump();
+ }
+
+ // Afterward, dump exception
+ const char *file = strchr(m_path.c_str(), '/');
+
+ if (file == NULL) {
+ file = m_path.c_str();
+ } else {
+ ++file;
+ }
+
+ printf("\033[0;36m[%s:%i]\033[m %s() \033[4;35m%s\033[m: %s\033[m\n",
+ file, m_line,
+ m_function.c_str(),
+ m_className.c_str(),
+ m_message.empty() ? "<EMPTY>" : m_message.c_str());
+ }
+
+ std::string DumpToString() const
+ {
+ std::string ret;
+
+ if (m_reason != NULL) {
+ ret = m_reason->DumpToString();
+ }
+
+ const char *file = strchr(m_path.c_str(), '/');
+
+ if (file == NULL) {
+ file = m_path.c_str();
+ } else {
+ ++file;
+ }
+
+ char buf[1024];
+ snprintf(buf,
+ sizeof(buf),
+ "\033[0;36m[%s:%i]\033[m %s() \033[4;35m%s\033[m: %s\033[m\n",
+ file,
+ m_line,
+ m_function.c_str(),
+ m_className.c_str(),
+ m_message.empty() ? "<EMPTY>" : m_message.c_str());
+ buf[sizeof(buf) - 1] = '\n';
+ ret += buf;
+ return ret;
+ }
+
+ Exception *GetReason() const
+ {
+ return m_reason;
+ }
+
+ std::string GetPath() const
+ {
+ return m_path;
+ }
+
+ std::string GetFunction() const
+ {
+ return m_function;
+ }
+
+ int GetLine() const
+ {
+ return m_line;
+ }
+
+ std::string GetMessage() const
+ {
+ return m_message;
+ }
+
+ std::string GetClassName() const
+ {
+ return m_className;
+ }
};
} // namespace CCHECKER
#define Try try
#define Throw(ClassName) \
- throw ClassName(__FILE__, __FUNCTION__, __LINE__)
+ throw ClassName(__FILE__, __FUNCTION__, __LINE__)
#define ThrowMsg(ClassName, Message) \
- do \
- { \
- std::ostringstream dplLoggingStream; \
- dplLoggingStream << Message; \
- throw ClassName(__FILE__, __FUNCTION__, __LINE__, dplLoggingStream.str()); \
- } while (0)
+ do \
+ { \
+ std::ostringstream dplLoggingStream; \
+ dplLoggingStream << Message; \
+ throw ClassName(__FILE__, __FUNCTION__, __LINE__, dplLoggingStream.str()); \
+ } while (0)
#define ReThrow(ClassName) \
- throw ClassName(__FILE__, __FUNCTION__, __LINE__, _rethrown_exception)
+ throw ClassName(__FILE__, __FUNCTION__, __LINE__, _rethrown_exception)
#define ReThrowMsg(ClassName, Message) \
- throw ClassName(__FILE__, \
- __FUNCTION__, \
- __LINE__, \
- _rethrown_exception, \
- Message)
+ throw ClassName(__FILE__, \
+ __FUNCTION__, \
+ __LINE__, \
+ _rethrown_exception, \
+ Message)
#define Catch(ClassName) \
- catch (const ClassName &_rethrown_exception)
+ catch (const ClassName &_rethrown_exception)
#define DECLARE_EXCEPTION_TYPE(BaseClass, Class) \
- class Class : \
- public BaseClass \
- { \
- public: \
- Class(const char *path, \
- const char *function, \
- int line, \
- const std::string & message = std::string()) : \
- BaseClass(path, function, line, message) \
- { \
- BaseClass::m_className = #Class; \
- } \
- \
- Class(const char *path, \
- const char *function, \
- int line, \
- const CCHECKER::Exception & reason, \
- const std::string & message = std::string()) : \
- BaseClass(path, function, line, reason, message) \
- { \
- BaseClass::m_className = #Class; \
- } \
- };
+ class Class : \
+ public BaseClass \
+ { \
+ public: \
+ Class(const char *path, \
+ const char *function, \
+ int line, \
+ const std::string & message = std::string()) : \
+ BaseClass(path, function, line, message) \
+ { \
+ BaseClass::m_className = #Class; \
+ } \
+ \
+ Class(const char *path, \
+ const char *function, \
+ int line, \
+ const CCHECKER::Exception & reason, \
+ const std::string & message = std::string()) : \
+ BaseClass(path, function, line, reason, message) \
+ { \
+ BaseClass::m_className = #Class; \
+ } \
+ };
#define UNHANDLED_EXCEPTION_HANDLER_BEGIN try
#define UNHANDLED_EXCEPTION_HANDLER_END \
- catch (const CCHECKER::Exception &exception) \
- { \
- std::ostringstream msg; \
- msg << CCHECKER::Exception::KnownExceptionToString(exception); \
- CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
- abort(); \
- } \
- catch (std::exception& e) \
- { \
- std::ostringstream msg; \
- msg << e.what(); \
- msg << "\n"; \
- msg << CCHECKER::Exception::UnknownExceptionToString(); \
- CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
- abort(); \
- } \
- catch (...) \
- { \
- std::ostringstream msg; \
- msg << CCHECKER::Exception::UnknownExceptionToString(); \
- CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
- abort(); \
- }
+ catch (const CCHECKER::Exception &exception) \
+ { \
+ std::ostringstream msg; \
+ msg << CCHECKER::Exception::KnownExceptionToString(exception); \
+ CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
+ abort(); \
+ } \
+ catch (std::exception& e) \
+ { \
+ std::ostringstream msg; \
+ msg << e.what(); \
+ msg << "\n"; \
+ msg << CCHECKER::Exception::UnknownExceptionToString(); \
+ CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
+ abort(); \
+ } \
+ catch (...) \
+ { \
+ std::ostringstream msg; \
+ msg << CCHECKER::Exception::UnknownExceptionToString(); \
+ CCHECKER::LogUnhandledException(msg.str(), __FILE__, __LINE__, __FUNCTION__); \
+ abort(); \
+ }
namespace CCHECKER {
namespace CommonException {
@@ -377,8 +368,8 @@ namespace CommonException {
* important messages.
*/
DECLARE_EXCEPTION_TYPE(Exception, InternalError) ///< Unexpected error from
- // underlying libraries or
- // kernel
+// underlying libraries or
+// kernel
}
}
diff --git a/src/dpl/core/include/cchecker/dpl/noncopyable.h b/src/dpl/core/include/cchecker/dpl/noncopyable.h
index 747299c..47fc8b3 100644
--- a/src/dpl/core/include/cchecker/dpl/noncopyable.h
+++ b/src/dpl/core/include/cchecker/dpl/noncopyable.h
@@ -23,15 +23,14 @@
#define CCHECKER_NONCOPYABLE_H
namespace CCHECKER {
-class Noncopyable
-{
- private:
- Noncopyable(const Noncopyable &);
- const Noncopyable &operator=(const Noncopyable &);
+class Noncopyable {
+private:
+ Noncopyable(const Noncopyable &);
+ const Noncopyable &operator=(const Noncopyable &);
- public:
- Noncopyable();
- virtual ~Noncopyable();
+public:
+ Noncopyable();
+ virtual ~Noncopyable();
};
} // namespace CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/optional.h b/src/dpl/core/include/cchecker/dpl/optional.h
index 42d1bd4..0f19d86 100644
--- a/src/dpl/core/include/cchecker/dpl/optional.h
+++ b/src/dpl/core/include/cchecker/dpl/optional.h
@@ -26,135 +26,137 @@
namespace CCHECKER {
template <typename Type>
-class Optional
-{
- class Exception
- {
- public:
- DECLARE_EXCEPTION_TYPE(CCHECKER::Exception, Base)
- DECLARE_EXCEPTION_TYPE(Base, NullReference)
- };
-
- public:
- Optional() :
- m_null(true),
- m_value()
- {}
-
- Optional(const Type& t) :
- m_null(false),
- m_value(t)
- {}
-
- bool IsNull() const
- {
- return m_null;
- }
-
- Type& operator*()
- {
- if (m_null) {
- Throw(typename Exception::NullReference);
- }
- return m_value;
- }
-
- const Type& operator*() const
- {
- if (m_null) {
- Throw(typename Exception::NullReference);
- }
- return m_value;
- }
-
- const Type* operator->() const
- {
- if (m_null) {
- Throw(typename Exception::NullReference);
- }
- return &m_value;
- }
-
- Type* operator->()
- {
- if (m_null) {
- Throw(typename Exception::NullReference);
- }
- return &m_value;
- }
-
- bool operator!() const
- {
- return m_null;
- }
-
- Optional<Type>& operator=(const Type& other)
- {
- m_null = false;
- m_value = other;
- return *this;
- }
-
- bool operator==(const Optional<Type>& aSecond) const
- {
- return LogicalOperator<true>(*this, aSecond,
- std::equal_to<Type>(), std::equal_to<bool>());
- }
-
- bool operator==(const Type& aSecond) const
- {
- return Optional<Type>(aSecond) == *this;
- }
-
- bool operator!=(const Optional<Type>& aSecond) const
- {
- return !(*this == aSecond);
- }
-
- bool operator<(const Optional<Type>& aSecond) const
- {
- return LogicalOperator<false>(*this, aSecond,
- std::less<Type>(), std::less<bool>());
- }
-
- bool operator>(const Optional<Type>& aSecond) const
- {
- return LogicalOperator<false>(*this, aSecond,
- std::greater<Type>(), std::greater<bool>());
- }
-
- bool operator<=(const Optional<Type>& aSecond) const
- {
- return *this == aSecond || *this < aSecond;
- }
-
- bool operator>=(const Optional<Type>& aSecond) const
- {
- return *this == aSecond || *this > aSecond;
- }
-
- static Optional<Type> Null;
-
- private:
- bool m_null;
- Type m_value;
-
- template <bool taEquality, typename taComparator, typename taNullComparator>
- static bool LogicalOperator(const Optional<Type>& aFirst,
- const Optional<Type>& aSecond,
- taComparator aComparator,
- taNullComparator aNullComparator)
- {
- if (aFirst.m_null == aSecond.m_null) {
- if (aFirst.m_null) {
- return taEquality;
- } else {
- return aComparator(aFirst.m_value, aSecond.m_value);
- }
- } else {
- return aNullComparator(aFirst.m_null, aSecond.m_null);
- }
- }
+class Optional {
+ class Exception {
+ public:
+ DECLARE_EXCEPTION_TYPE(CCHECKER::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, NullReference)
+ };
+
+public:
+ Optional() :
+ m_null(true),
+ m_value()
+ {}
+
+ Optional(const Type &t) :
+ m_null(false),
+ m_value(t)
+ {}
+
+ bool IsNull() const
+ {
+ return m_null;
+ }
+
+ Type &operator*()
+ {
+ if (m_null) {
+ Throw(typename Exception::NullReference);
+ }
+
+ return m_value;
+ }
+
+ const Type &operator*() const
+ {
+ if (m_null) {
+ Throw(typename Exception::NullReference);
+ }
+
+ return m_value;
+ }
+
+ const Type *operator->() const
+ {
+ if (m_null) {
+ Throw(typename Exception::NullReference);
+ }
+
+ return &m_value;
+ }
+
+ Type *operator->()
+ {
+ if (m_null) {
+ Throw(typename Exception::NullReference);
+ }
+
+ return &m_value;
+ }
+
+ bool operator!() const
+ {
+ return m_null;
+ }
+
+ Optional<Type> &operator=(const Type &other)
+ {
+ m_null = false;
+ m_value = other;
+ return *this;
+ }
+
+ bool operator==(const Optional<Type> &aSecond) const
+ {
+ return LogicalOperator<true>(*this, aSecond,
+ std::equal_to<Type>(), std::equal_to<bool>());
+ }
+
+ bool operator==(const Type &aSecond) const
+ {
+ return Optional<Type>(aSecond) == *this;
+ }
+
+ bool operator!=(const Optional<Type> &aSecond) const
+ {
+ return !(*this == aSecond);
+ }
+
+ bool operator<(const Optional<Type> &aSecond) const
+ {
+ return LogicalOperator<false>(*this, aSecond,
+ std::less<Type>(), std::less<bool>());
+ }
+
+ bool operator>(const Optional<Type> &aSecond) const
+ {
+ return LogicalOperator<false>(*this, aSecond,
+ std::greater<Type>(), std::greater<bool>());
+ }
+
+ bool operator<=(const Optional<Type> &aSecond) const
+ {
+ return *this == aSecond || *this < aSecond;
+ }
+
+ bool operator>=(const Optional<Type> &aSecond) const
+ {
+ return *this == aSecond || *this > aSecond;
+ }
+
+ static Optional<Type> Null;
+
+private:
+ bool m_null;
+ Type m_value;
+
+ template <bool taEquality, typename taComparator, typename taNullComparator>
+ static bool LogicalOperator(const Optional<Type> &aFirst,
+ const Optional<Type> &aSecond,
+ taComparator aComparator,
+ taNullComparator aNullComparator)
+ {
+ if (aFirst.m_null == aSecond.m_null) {
+ if (aFirst.m_null) {
+ return taEquality;
+ } else {
+ return aComparator(aFirst.m_value, aSecond.m_value);
+ }
+ } else {
+ return aNullComparator(aFirst.m_null, aSecond.m_null);
+ }
+ }
};
template<typename Type>
@@ -162,14 +164,14 @@ Optional<Type> Optional<Type>::Null = Optional<Type>();
} //namespace CCHECKER
template<typename Type>
-std::ostream& operator<<(std::ostream& aStream,
- const CCHECKER::Optional<Type>& aOptional)
+std::ostream &operator<<(std::ostream &aStream,
+ const CCHECKER::Optional<Type> &aOptional)
{
- if (aOptional.IsNull()) {
- return aStream << "null optional";
- } else {
- return aStream << *aOptional;
- }
+ if (aOptional.IsNull()) {
+ return aStream << "null optional";
+ } else {
+ return aStream << *aOptional;
+ }
}
#endif // CCHECKER_OPTIONAL_VALUE_H
diff --git a/src/dpl/core/include/cchecker/dpl/scoped_array.h b/src/dpl/core/include/cchecker/dpl/scoped_array.h
index 54c0c80..f38ae83 100644
--- a/src/dpl/core/include/cchecker/dpl/scoped_array.h
+++ b/src/dpl/core/include/cchecker/dpl/scoped_array.h
@@ -29,36 +29,33 @@
namespace CCHECKER {
template<typename Class>
-struct ScopedArrayPolicy
-{
- typedef Class* Type;
- static Type NullValue()
- {
- return NULL;
- }
- static void Destroy(Type ptr)
- {
- delete[] ptr;
- }
+struct ScopedArrayPolicy {
+ typedef Class *Type;
+ static Type NullValue()
+ {
+ return NULL;
+ }
+ static void Destroy(Type ptr)
+ {
+ delete[] ptr;
+ }
};
template<typename Class>
-class ScopedArray : public ScopedResource<ScopedArrayPolicy<Class> >
-{
- typedef ScopedArrayPolicy<Class> Policy;
- typedef ScopedResource<Policy> BaseType;
-
- public:
- explicit ScopedArray(Class *ptr = Policy::NullValue()) : BaseType(ptr) { }
-
- Class &operator [](std::ptrdiff_t k) const
- {
- Assert(this->m_value != Policy::NullValue() &&
- "Dereference of scoped NULL array!");
- Assert(k >= 0 && "Negative array index");
-
- return this->m_value[k];
- }
+class ScopedArray : public ScopedResource<ScopedArrayPolicy<Class>> {
+ typedef ScopedArrayPolicy<Class> Policy;
+ typedef ScopedResource<Policy> BaseType;
+
+public:
+ explicit ScopedArray(Class *ptr = Policy::NullValue()) : BaseType(ptr) { }
+
+ Class &operator[](std::ptrdiff_t k) const
+ {
+ Assert(this->m_value != Policy::NullValue() &&
+ "Dereference of scoped NULL array!");
+ Assert(k >= 0 && "Negative array index");
+ return this->m_value[k];
+ }
};
} // namespace CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/scoped_free.h b/src/dpl/core/include/cchecker/dpl/scoped_free.h
index d8fee50..72b0ae0 100644
--- a/src/dpl/core/include/cchecker/dpl/scoped_free.h
+++ b/src/dpl/core/include/cchecker/dpl/scoped_free.h
@@ -30,27 +30,25 @@
namespace CCHECKER {
template<typename Class>
-struct ScopedFreePolicy
-{
- typedef Class* Type;
- static Type NullValue()
- {
- return NULL;
- }
- static void Destroy(Type ptr)
- {
- free(ptr);
- }
+struct ScopedFreePolicy {
+ typedef Class *Type;
+ static Type NullValue()
+ {
+ return NULL;
+ }
+ static void Destroy(Type ptr)
+ {
+ free(ptr);
+ }
};
template<typename Memory>
-class ScopedFree : public ScopedResource<ScopedFreePolicy<Memory> >
-{
- typedef ScopedFreePolicy<Memory> Policy;
- typedef ScopedResource<Policy> BaseType;
+class ScopedFree : public ScopedResource<ScopedFreePolicy<Memory>> {
+ typedef ScopedFreePolicy<Memory> Policy;
+ typedef ScopedResource<Policy> BaseType;
- public:
- explicit ScopedFree(Memory *ptr = Policy::NullValue()) : BaseType(ptr) { }
+public:
+ explicit ScopedFree(Memory *ptr = Policy::NullValue()) : BaseType(ptr) { }
};
} // namespace CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/scoped_resource.h b/src/dpl/core/include/cchecker/dpl/scoped_resource.h
index 2b3c72d..42aef36 100644
--- a/src/dpl/core/include/cchecker/dpl/scoped_resource.h
+++ b/src/dpl/core/include/cchecker/dpl/scoped_resource.h
@@ -27,53 +27,52 @@
namespace CCHECKER {
template<typename ClassPolicy>
class ScopedResource :
- private Noncopyable
-{
- public:
- typedef typename ClassPolicy::Type ValueType;
- typedef ScopedResource<ClassPolicy> ThisType;
+ private Noncopyable {
+public:
+ typedef typename ClassPolicy::Type ValueType;
+ typedef ScopedResource<ClassPolicy> ThisType;
- protected:
- ValueType m_value;
+protected:
+ ValueType m_value;
- public:
- explicit ScopedResource(ValueType value) : m_value(value) { }
+public:
+ explicit ScopedResource(ValueType value) : m_value(value) { }
- ~ScopedResource()
- {
- ClassPolicy::Destroy(m_value);
- }
+ ~ScopedResource()
+ {
+ ClassPolicy::Destroy(m_value);
+ }
- ValueType Get() const
- {
- return m_value;
- }
+ ValueType Get() const
+ {
+ return m_value;
+ }
- void Reset(ValueType value = ClassPolicy::NullValue())
- {
- ClassPolicy::Destroy(m_value);
- m_value = value;
- }
+ void Reset(ValueType value = ClassPolicy::NullValue())
+ {
+ ClassPolicy::Destroy(m_value);
+ m_value = value;
+ }
- ValueType Release()
- {
- ValueType value = m_value;
- m_value = ClassPolicy::NullValue();
- return value;
- }
- typedef ValueType ThisType::*UnknownBoolType;
+ ValueType Release()
+ {
+ ValueType value = m_value;
+ m_value = ClassPolicy::NullValue();
+ return value;
+ }
+ typedef ValueType ThisType::*UnknownBoolType;
- operator UnknownBoolType() const
- {
- return m_value == ClassPolicy::NullValue() ?
- 0 : //0 is valid here because it converts to false
- &ThisType::m_value; //it converts to true
- }
+ operator UnknownBoolType() const
+ {
+ return m_value == ClassPolicy::NullValue() ?
+ 0 : //0 is valid here because it converts to false
+ &ThisType::m_value; //it converts to true
+ }
- bool operator !() const
- {
- return m_value == ClassPolicy::NullValue();
- }
+ bool operator !() const
+ {
+ return m_value == ClassPolicy::NullValue();
+ }
};
} // namespace CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/serialization.h b/src/dpl/core/include/cchecker/dpl/serialization.h
index 5628350..c39ca09 100644
--- a/src/dpl/core/include/cchecker/dpl/serialization.h
+++ b/src/dpl/core/include/cchecker/dpl/serialization.h
@@ -32,423 +32,424 @@
namespace CCHECKER {
// Abstract data stream buffer
-class IStream
-{
- public:
- virtual void Read(size_t num, void * bytes) = 0;
- virtual void Write(size_t num, const void * bytes) = 0;
- virtual ~IStream(){}
+class IStream {
+public:
+ virtual void Read(size_t num, void *bytes) = 0;
+ virtual void Write(size_t num, const void *bytes) = 0;
+ virtual ~IStream() {}
};
// Serializable interface
-class ISerializable
-{
- public:
- /* ISerializable(){};
- * ISerializable(IStream&){}; */
- virtual void Serialize(IStream &) const = 0;
- virtual ~ISerializable(){}
+class ISerializable {
+public:
+ /* ISerializable(){};
+ * ISerializable(IStream&){}; */
+ virtual void Serialize(IStream &) const = 0;
+ virtual ~ISerializable() {}
};
struct Serialization {
- // serialization
- // normal functions
-
- // ISerializable objects
- static void Serialize(IStream& stream, const ISerializable& object)
- {
- object.Serialize(stream);
- }
-
- static void Serialize(IStream& stream, const ISerializable* const object)
- {
- object->Serialize(stream);
- }
-
- // char
- static void Serialize(IStream& stream, const char value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const char* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // unsigned char
- static void Serialize(IStream& stream, const unsigned char value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const unsigned char* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // unsigned int32
- static void Serialize(IStream& stream, const uint32_t value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const uint32_t* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // int32
- static void Serialize(IStream& stream, const int32_t value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const int32_t* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // unsigned int64
- static void Serialize(IStream& stream, const uint64_t value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const uint64_t* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // int64
- static void Serialize(IStream& stream, const int64_t value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const int64_t* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // bool
- static void Serialize(IStream& stream, const bool value)
- {
- stream.Write(sizeof(value), &value);
- }
- static void Serialize(IStream& stream, const bool* const value)
- {
- stream.Write(sizeof(*value), value);
- }
-
- // std::string
- template <typename T, typename R, typename A>
- static void Serialize(IStream& stream, const std::basic_string<T,R,A>& str)
- {
- int length = str.size();
- stream.Write(sizeof(length), &length);
- stream.Write(length*sizeof(T), str.data());
- }
-
- template<typename T, typename R, typename A>
- static void Serialize(IStream& stream, const std::basic_string<T,R,A>* const str)
- {
- int length = str->size();
- stream.Write(sizeof(length), &length);
- stream.Write(length*sizeof(T), str->data());
- }
-
- // STL templates
-
- // std::list
- template <typename T>
- static void Serialize(IStream& stream, const std::list<T>& list)
- {
- int length = list.size();
- stream.Write(sizeof(length), &length);
- for (typename std::list<T>::const_iterator list_iter = list.begin();
- list_iter != list.end(); list_iter++)
- {
- Serialize(stream, *list_iter);
- }
- }
- template <typename T>
- static void Serialize(IStream& stream, const std::list<T>* const list)
- {
- Serialize(stream, *list);
- }
-
- // RawBuffer
- template <typename A>
- static void Serialize(IStream& stream, const std::vector<unsigned char, A>& vec)
- {
- int length = vec.size();
- stream.Write(sizeof(length), &length);
- stream.Write(length, vec.data());
- }
-
- template <typename A>
- static void Serialize(IStream& stream, const std::vector<unsigned char, A>* const vec)
- {
- Serialize(stream, *vec);
- }
-
- // std::vector
- template <typename T, typename A>
- static void Serialize(IStream& stream, const std::vector<T, A>& vec)
- {
- int length = vec.size();
- stream.Write(sizeof(length), &length);
- for (const auto &i : vec)
- {
- Serialize(stream, i);
- }
- }
- template <typename T, typename A>
- static void Serialize(IStream& stream, const std::vector<T, A>* const vec)
- {
- Serialize(stream, *vec);
- }
-
- // std::pair
- template <typename A, typename B>
- static void Serialize(IStream& stream, const std::pair<A, B>& p)
- {
- Serialize(stream, p.first);
- Serialize(stream, p.second);
- }
- template <typename A, typename B>
- static void Serialize(IStream& stream, const std::pair<A, B>* const p)
- {
- Serialize(stream, *p);
- }
-
- // std::map
- template <typename K, typename T>
- static void Serialize(IStream& stream, const std::map<K, T>& map)
- {
- int length = map.size();
- stream.Write(sizeof(length), &length);
- typename std::map<K, T>::const_iterator it;
- for (it = map.begin(); it != map.end(); ++it) {
- Serialize(stream, (*it).first);
- Serialize(stream, (*it).second);
- }
- }
- template <typename K, typename T>
- static void Serialize(IStream& stream, const std::map<K, T>* const map)
- {
- Serialize(stream, *map);
- }
-
- // std::unique_ptr
- template <typename T>
- static void Serialize(IStream& stream, const std::unique_ptr<T>& p)
- {
- Serialize(stream, *p);
- }
-
+ // serialization
+ // normal functions
+
+ // ISerializable objects
+ static void Serialize(IStream &stream, const ISerializable &object)
+ {
+ object.Serialize(stream);
+ }
+
+ static void Serialize(IStream &stream, const ISerializable *const object)
+ {
+ object->Serialize(stream);
+ }
+
+ // char
+ static void Serialize(IStream &stream, const char value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const char *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // unsigned char
+ static void Serialize(IStream &stream, const unsigned char value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const unsigned char *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // unsigned int32
+ static void Serialize(IStream &stream, const uint32_t value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const uint32_t *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // int32
+ static void Serialize(IStream &stream, const int32_t value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const int32_t *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // unsigned int64
+ static void Serialize(IStream &stream, const uint64_t value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const uint64_t *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // int64
+ static void Serialize(IStream &stream, const int64_t value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const int64_t *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // bool
+ static void Serialize(IStream &stream, const bool value)
+ {
+ stream.Write(sizeof(value), &value);
+ }
+ static void Serialize(IStream &stream, const bool *const value)
+ {
+ stream.Write(sizeof(*value), value);
+ }
+
+ // std::string
+ template <typename T, typename R, typename A>
+ static void Serialize(IStream &stream, const std::basic_string<T, R, A> &str)
+ {
+ int length = str.size();
+ stream.Write(sizeof(length), &length);
+ stream.Write(length * sizeof(T), str.data());
+ }
+
+ template<typename T, typename R, typename A>
+ static void Serialize(IStream &stream, const std::basic_string<T, R, A> *const str)
+ {
+ int length = str->size();
+ stream.Write(sizeof(length), &length);
+ stream.Write(length * sizeof(T), str->data());
+ }
+
+ // STL templates
+
+ // std::list
+ template <typename T>
+ static void Serialize(IStream &stream, const std::list<T> &list)
+ {
+ int length = list.size();
+ stream.Write(sizeof(length), &length);
+
+ for (typename std::list<T>::const_iterator list_iter = list.begin();
+ list_iter != list.end(); list_iter++) {
+ Serialize(stream, *list_iter);
+ }
+ }
+ template <typename T>
+ static void Serialize(IStream &stream, const std::list<T> *const list)
+ {
+ Serialize(stream, *list);
+ }
+
+ // RawBuffer
+ template <typename A>
+ static void Serialize(IStream &stream, const std::vector<unsigned char, A> &vec)
+ {
+ int length = vec.size();
+ stream.Write(sizeof(length), &length);
+ stream.Write(length, vec.data());
+ }
+
+ template <typename A>
+ static void Serialize(IStream &stream, const std::vector<unsigned char, A> *const vec)
+ {
+ Serialize(stream, *vec);
+ }
+
+ // std::vector
+ template <typename T, typename A>
+ static void Serialize(IStream &stream, const std::vector<T, A> &vec)
+ {
+ int length = vec.size();
+ stream.Write(sizeof(length), &length);
+
+ for (const auto &i : vec) {
+ Serialize(stream, i);
+ }
+ }
+ template <typename T, typename A>
+ static void Serialize(IStream &stream, const std::vector<T, A> *const vec)
+ {
+ Serialize(stream, *vec);
+ }
+
+ // std::pair
+ template <typename A, typename B>
+ static void Serialize(IStream &stream, const std::pair<A, B> &p)
+ {
+ Serialize(stream, p.first);
+ Serialize(stream, p.second);
+ }
+ template <typename A, typename B>
+ static void Serialize(IStream &stream, const std::pair<A, B> *const p)
+ {
+ Serialize(stream, *p);
+ }
+
+ // std::map
+ template <typename K, typename T>
+ static void Serialize(IStream &stream, const std::map<K, T> &map)
+ {
+ int length = map.size();
+ stream.Write(sizeof(length), &length);
+ typename std::map<K, T>::const_iterator it;
+
+ for (it = map.begin(); it != map.end(); ++it) {
+ Serialize(stream, (*it).first);
+ Serialize(stream, (*it).second);
+ }
+ }
+ template <typename K, typename T>
+ static void Serialize(IStream &stream, const std::map<K, T> *const map)
+ {
+ Serialize(stream, *map);
+ }
+
+ // std::unique_ptr
+ template <typename T>
+ static void Serialize(IStream &stream, const std::unique_ptr<T> &p)
+ {
+ Serialize(stream, *p);
+ }
}; // struct Serialization
struct Deserialization {
- // deserialization
- // normal functions
-
- // ISerializable objects
- // T instead of ISerializable is needed to call proper constructor
- template <typename T>
- static void Deserialize(IStream& stream, T& object)
- {
- object = T(stream);
- }
- template <typename T>
- static void Deserialize(IStream& stream, T*& object)
- {
- object = new T(stream);
- }
-
- // char
- static void Deserialize(IStream& stream, char& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, char*& value)
- {
- value = new char;
- stream.Read(sizeof(*value), value);
- }
-
- // unsigned char
- static void Deserialize(IStream& stream, unsigned char& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, unsigned char*& value)
- {
- value = new unsigned char;
- stream.Read(sizeof(*value), value);
- }
-
- // unsigned int32
- static void Deserialize(IStream& stream, uint32_t& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, uint32_t*& value)
- {
- value = new uint32_t;
- stream.Read(sizeof(*value), value);
- }
-
- // int32
- static void Deserialize(IStream& stream, int32_t& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, int32_t*& value)
- {
- value = new int32_t;
- stream.Read(sizeof(*value), value);
- }
-
- // unsigned int64
- static void Deserialize(IStream& stream, uint64_t& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, uint64_t*& value)
- {
- value = new uint64_t;
- stream.Read(sizeof(*value), value);
- }
-
- // int64
- static void Deserialize(IStream& stream, int64_t& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, int64_t*& value)
- {
- value = new int64_t;
- stream.Read(sizeof(*value), value);
- }
-
- // bool
- static void Deserialize(IStream& stream, bool& value)
- {
- stream.Read(sizeof(value), &value);
- }
- static void Deserialize(IStream& stream, bool*& value)
- {
- value = new bool;
- stream.Read(sizeof(*value), value);
- }
-
- template <typename T, typename R, typename A>
- static void Deserialize(IStream& stream, std::basic_string<T,R,A>& str)
- {
- int length;
- stream.Read(sizeof(length), &length);
- std::vector<T> buf(length);
- stream.Read(length*sizeof(T), buf.data());
- str = std::basic_string<T,R,A>(buf.data(), buf.data()+length);
- }
-
- template <typename T, typename R, typename A>
- static void Deserialize(IStream& stream, std::basic_string<T,R,A>*& str)
- {
- int length;
- stream.Read(sizeof(length), &length);
- std::vector<T> buf(length);
- stream.Read(length*sizeof(T), buf.data());
- str = new std::basic_string<T,R,A>(buf.data(), buf.data()+length);
- }
-
- // STL templates
-
- // std::list
- template <typename T>
- static void Deserialize(IStream& stream, std::list<T>& list)
- {
- int length;
- stream.Read(sizeof(length), &length);
- for (int i = 0; i < length; ++i) {
- T obj;
- Deserialize(stream, obj);
- list.push_back(std::move(obj));
- }
- }
- template <typename T>
- static void Deserialize(IStream& stream, std::list<T>*& list)
- {
- list = new std::list<T>;
- Deserialize(stream, *list);
- }
-
- // RawBuffer
- template <typename A>
- static void Deserialize(IStream& stream, std::vector<unsigned char, A>& vec)
- {
- int length;
- stream.Read(sizeof(length), &length);
- vec.resize(length);
- stream.Read(length, vec.data());
- }
-
- template <typename A>
- static void Deserialize(IStream& stream, std::vector<unsigned char, A>*& vec)
- {
- vec = new std::vector<unsigned char,A>;
- Deserialize(stream, *vec);
- }
-
- // std::vector
- template <typename T, typename A>
- static void Deserialize(IStream& stream, std::vector<T,A>& vec)
- {
- int length;
- stream.Read(sizeof(length), &length);
- for (int i = 0; i < length; ++i) {
- T obj;
- Deserialize(stream, obj);
- vec.push_back(std::move(obj));
- }
- }
- template <typename T, typename A>
- static void Deserialize(IStream& stream, std::vector<T,A>*& vec)
- {
- vec = new std::vector<T,A>;
- Deserialize(stream, *vec);
- }
-
- // std::pair
- template <typename A, typename B>
- static void Deserialize(IStream& stream, std::pair<A, B>& p)
- {
- Deserialize(stream, p.first);
- Deserialize(stream, p.second);
- }
- template <typename A, typename B>
- static void Deserialize(IStream& stream, std::pair<A, B>*& p)
- {
- p = new std::pair<A, B>;
- Deserialize(stream, *p);
- }
-
- // std::map
- template <typename K, typename T>
- static void Deserialize(IStream& stream, std::map<K, T>& map)
- {
- int length;
- stream.Read(sizeof(length), &length);
- for (int i = 0; i < length; ++i) {
- K key;
- T obj;
- Deserialize(stream, key);
- Deserialize(stream, obj);
- map[key] = std::move(obj);
- }
- }
- template <typename K, typename T>
- static void Deserialize(IStream& stream, std::map<K, T>*& map)
- {
- map = new std::map<K, T>;
- Deserialize(stream, *map);
- }
+ // deserialization
+ // normal functions
+
+ // ISerializable objects
+ // T instead of ISerializable is needed to call proper constructor
+ template <typename T>
+ static void Deserialize(IStream &stream, T &object)
+ {
+ object = T(stream);
+ }
+ template <typename T>
+ static void Deserialize(IStream &stream, T *&object)
+ {
+ object = new T(stream);
+ }
+
+ // char
+ static void Deserialize(IStream &stream, char &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, char *&value)
+ {
+ value = new char;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // unsigned char
+ static void Deserialize(IStream &stream, unsigned char &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, unsigned char *&value)
+ {
+ value = new unsigned char;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // unsigned int32
+ static void Deserialize(IStream &stream, uint32_t &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, uint32_t *&value)
+ {
+ value = new uint32_t;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // int32
+ static void Deserialize(IStream &stream, int32_t &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, int32_t *&value)
+ {
+ value = new int32_t;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // unsigned int64
+ static void Deserialize(IStream &stream, uint64_t &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, uint64_t *&value)
+ {
+ value = new uint64_t;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // int64
+ static void Deserialize(IStream &stream, int64_t &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, int64_t *&value)
+ {
+ value = new int64_t;
+ stream.Read(sizeof(*value), value);
+ }
+
+ // bool
+ static void Deserialize(IStream &stream, bool &value)
+ {
+ stream.Read(sizeof(value), &value);
+ }
+ static void Deserialize(IStream &stream, bool *&value)
+ {
+ value = new bool;
+ stream.Read(sizeof(*value), value);
+ }
+
+ template <typename T, typename R, typename A>
+ static void Deserialize(IStream &stream, std::basic_string<T, R, A> &str)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+ std::vector<T> buf(length);
+ stream.Read(length * sizeof(T), buf.data());
+ str = std::basic_string<T, R, A>(buf.data(), buf.data() + length);
+ }
+
+ template <typename T, typename R, typename A>
+ static void Deserialize(IStream &stream, std::basic_string<T, R, A> *&str)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+ std::vector<T> buf(length);
+ stream.Read(length * sizeof(T), buf.data());
+ str = new std::basic_string<T, R, A>(buf.data(), buf.data() + length);
+ }
+
+ // STL templates
+
+ // std::list
+ template <typename T>
+ static void Deserialize(IStream &stream, std::list<T> &list)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+
+ for (int i = 0; i < length; ++i) {
+ T obj;
+ Deserialize(stream, obj);
+ list.push_back(std::move(obj));
+ }
+ }
+ template <typename T>
+ static void Deserialize(IStream &stream, std::list<T> *&list)
+ {
+ list = new std::list<T>;
+ Deserialize(stream, *list);
+ }
+
+ // RawBuffer
+ template <typename A>
+ static void Deserialize(IStream &stream, std::vector<unsigned char, A> &vec)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+ vec.resize(length);
+ stream.Read(length, vec.data());
+ }
+
+ template <typename A>
+ static void Deserialize(IStream &stream, std::vector<unsigned char, A> *&vec)
+ {
+ vec = new std::vector<unsigned char, A>;
+ Deserialize(stream, *vec);
+ }
+
+ // std::vector
+ template <typename T, typename A>
+ static void Deserialize(IStream &stream, std::vector<T, A> &vec)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+
+ for (int i = 0; i < length; ++i) {
+ T obj;
+ Deserialize(stream, obj);
+ vec.push_back(std::move(obj));
+ }
+ }
+ template <typename T, typename A>
+ static void Deserialize(IStream &stream, std::vector<T, A> *&vec)
+ {
+ vec = new std::vector<T, A>;
+ Deserialize(stream, *vec);
+ }
+
+ // std::pair
+ template <typename A, typename B>
+ static void Deserialize(IStream &stream, std::pair<A, B> &p)
+ {
+ Deserialize(stream, p.first);
+ Deserialize(stream, p.second);
+ }
+ template <typename A, typename B>
+ static void Deserialize(IStream &stream, std::pair<A, B> *&p)
+ {
+ p = new std::pair<A, B>;
+ Deserialize(stream, *p);
+ }
+
+ // std::map
+ template <typename K, typename T>
+ static void Deserialize(IStream &stream, std::map<K, T> &map)
+ {
+ int length;
+ stream.Read(sizeof(length), &length);
+
+ for (int i = 0; i < length; ++i) {
+ K key;
+ T obj;
+ Deserialize(stream, key);
+ Deserialize(stream, obj);
+ map[key] = std::move(obj);
+ }
+ }
+ template <typename K, typename T>
+ static void Deserialize(IStream &stream, std::map<K, T> *&map)
+ {
+ map = new std::map<K, T>;
+ Deserialize(stream, *map);
+ }
}; // struct Deserialization
// generic serialization
@@ -457,18 +458,20 @@ struct Serializer;
template <typename First, typename... Args>
struct Serializer<First, Args...> : public Serializer<Args...> {
- static void Serialize(IStream& stream, const First& f, const Args&... args) {
- Serialization::Serialize(stream, f);
- Serializer<Args...>::Serialize(stream, args...);
- }
+ static void Serialize(IStream &stream, const First &f, const Args &... args)
+ {
+ Serialization::Serialize(stream, f);
+ Serializer<Args...>::Serialize(stream, args...);
+ }
};
// end of recursion
template <>
struct Serializer<> {
- static void Serialize(IStream&) {
- return;
- }
+ static void Serialize(IStream &)
+ {
+ return;
+ }
};
// generic deserialization
@@ -477,18 +480,20 @@ struct Deserializer;
template <typename First, typename... Args>
struct Deserializer<First, Args...> : public Deserializer<Args...> {
- static void Deserialize(IStream& stream, First& f, Args&... args) {
- Deserialization::Deserialize(stream, f);
- Deserializer<Args...>::Deserialize(stream, args...);
- }
+ static void Deserialize(IStream &stream, First &f, Args &... args)
+ {
+ Deserialization::Deserialize(stream, f);
+ Deserializer<Args...>::Deserialize(stream, args...);
+ }
};
// end of recursion
template <>
struct Deserializer<> {
- static void Deserialize(IStream&) {
- return;
- }
+ static void Deserialize(IStream &)
+ {
+ return;
+ }
};
} // CCHECKER
diff --git a/src/dpl/core/include/cchecker/dpl/string.h b/src/dpl/core/include/cchecker/dpl/string.h
index d9c3bbd..5d12e17 100644
--- a/src/dpl/core/include/cchecker/dpl/string.h
+++ b/src/dpl/core/include/cchecker/dpl/string.h
@@ -33,47 +33,46 @@ namespace CCHECKER {
typedef std::basic_string<wchar_t, CharTraits> String;
// @brief String exception class
-class StringException
-{
- public:
- DECLARE_EXCEPTION_TYPE(CCHECKER::Exception, Base)
+class StringException {
+public:
+ DECLARE_EXCEPTION_TYPE(CCHECKER::Exception, Base)
- // @brief Invalid init for UTF8 to UTF32 converter
- DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF8ToUTF32)
+ // @brief Invalid init for UTF8 to UTF32 converter
+ DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF8ToUTF32)
- // @brief Invalid taStdContainerinit for UTF32 to UTF32 converter
- DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF32ToUTF8)
+ // @brief Invalid taStdContainerinit for UTF32 to UTF32 converter
+ DECLARE_EXCEPTION_TYPE(Base, IconvInitErrorUTF32ToUTF8)
- // @brief Invalid conversion for UTF8 to UTF32 converter
- DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF8ToUTF32)
+ // @brief Invalid conversion for UTF8 to UTF32 converter
+ DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF8ToUTF32)
- // @brief Invalid conversion for UTF8 to UTF32 converter
- DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF32ToUTF8)
+ // @brief Invalid conversion for UTF8 to UTF32 converter
+ DECLARE_EXCEPTION_TYPE(Base, IconvConvertErrorUTF32ToUTF8)
- // @brief Invalid ASCII character detected in FromASCII
- DECLARE_EXCEPTION_TYPE(Base, InvalidASCIICharacter)
+ // @brief Invalid ASCII character detected in FromASCII
+ DECLARE_EXCEPTION_TYPE(Base, InvalidASCIICharacter)
- // @brief Invalid ASCII character detected in FromASCII
- DECLARE_EXCEPTION_TYPE(Base, ICUInvalidCharacterFound)
+ // @brief Invalid ASCII character detected in FromASCII
+ DECLARE_EXCEPTION_TYPE(Base, ICUInvalidCharacterFound)
};
//!\brief convert ASCII string to CCHECKER::String
-String FromASCIIString(const std::string& aString);
+String FromASCIIString(const std::string &aString);
//!\brief convert UTF32 string to CCHECKER::String
-String FromUTF32String(const std::wstring& aString);
+String FromUTF32String(const std::wstring &aString);
//@brief Returns String object created from UTF8 string
//@param[in] aString input UTF-8 string
-String FromUTF8String(const std::string& aString);
+String FromUTF8String(const std::string &aString);
//@brief Returns String content as std::string
-std::string ToUTF8String(const String& aString);
+std::string ToUTF8String(const String &aString);
//@brief Compare two unicode strings
int StringCompare(const String &left,
- const String &right,
- bool caseInsensitive = false);
+ const String &right,
+ bool caseInsensitive = false);
//@brief Splits the string into substrings.
//@param[in] str Input string
@@ -81,61 +80,63 @@ int StringCompare(const String &left,
// delimiters. Can be also a single delimiter character.
//@param[in] it InserterIterator that is used to save the generated substrings.
template<typename StringType, typename Delimiters, typename InserterIterator>
-void Tokenize(const StringType& str,
- const Delimiters& delimiters,
- InserterIterator it,
- bool ignoreEmpty = false)
+void Tokenize(const StringType &str,
+ const Delimiters &delimiters,
+ InserterIterator it,
+ bool ignoreEmpty = false)
{
- typename StringType::size_type nextSearchStart = 0;
- typename StringType::size_type pos;
- typename StringType::size_type length;
-
- while (true) {
- pos = str.find_first_of(delimiters, nextSearchStart);
- length =
- ((pos == StringType::npos) ? str.length() : pos) - nextSearchStart;
-
- if (!ignoreEmpty || length > 0) {
- *it = str.substr(nextSearchStart, length);
- it++;
- }
-
- if (pos == StringType::npos) {
- return;
- }
-
- nextSearchStart = pos + 1;
- }
+ typename StringType::size_type nextSearchStart = 0;
+ typename StringType::size_type pos;
+ typename StringType::size_type length;
+
+ while (true) {
+ pos = str.find_first_of(delimiters, nextSearchStart);
+ length =
+ ((pos == StringType::npos) ? str.length() : pos) - nextSearchStart;
+
+ if (!ignoreEmpty || length > 0) {
+ *it = str.substr(nextSearchStart, length);
+ it++;
+ }
+
+ if (pos == StringType::npos) {
+ return;
+ }
+
+ nextSearchStart = pos + 1;
+ }
}
namespace Utils {
-template<typename T> class ConcatFunc : public std::binary_function<T, T, T>
-{
+template<typename T> class ConcatFunc : public std::binary_function<T, T, T> {
public:
- explicit ConcatFunc(const T & val) : m_delim(val) {}
- T operator()(const T & arg1, const T & arg2) const
- {
- return arg1 + m_delim + arg2;
- }
+ explicit ConcatFunc(const T &val) : m_delim(val) {}
+ T operator()(const T &arg1, const T &arg2) const
+ {
+ return arg1 + m_delim + arg2;
+ }
private:
- T m_delim;
+ T m_delim;
};
}
template<typename ForwardIterator>
-typename ForwardIterator::value_type Join(ForwardIterator begin, ForwardIterator end, typename ForwardIterator::value_type delim)
+typename ForwardIterator::value_type Join(ForwardIterator begin, ForwardIterator end,
+ typename ForwardIterator::value_type delim)
{
- typedef typename ForwardIterator::value_type value;
- if(begin == end) return value();
- Utils::ConcatFunc<value> func(delim);
- ForwardIterator init = begin;
- return std::accumulate(++begin, end, *init, func);
+ typedef typename ForwardIterator::value_type value;
+
+ if (begin == end) return value();
+
+ Utils::ConcatFunc<value> func(delim);
+ ForwardIterator init = begin;
+ return std::accumulate(++begin, end, *init, func);
}
} //namespace CCHECKER
-std::ostream& operator<<(std::ostream& aStream, const CCHECKER::String& aString);
+std::ostream &operator<<(std::ostream &aStream, const CCHECKER::String &aString);
#endif // CCHECKER_STRING