Update of /cvsroot/csp/APPLICATIONS/SimData/Include/SimData In directory sc8-pr-cvs1:/tmp/cvs-serv7755/Include/SimData Modified Files: Date.h Enum.h HashUtility.h InterfaceRegistry.h LogStream.h ObjectInterface.h hash_map.h Added Files: Singleton.h Trace.h Log Message: --- NEW FILE: Singleton.h --- /* SimData: Data Infrastructure for Simulations * Copyright (C) 2003 Mark Rose <tm...@st...> * * This file is part of SimData. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file Singleton.h * @brief Pattern for creating single global instances. */ #ifndef __SIMDATA_SINGLETON_H__ #define __SIMDATA_SINGLETON_H__ #include <SimData/Namespace.h> NAMESPACE_SIMDATA /** Creates a single, static instance of the templated class. */ template <class C> class Singleton { public: /** Get the one instance of the template class. */ static C& getInstance() { static C __instance; return __instance; } private: Singleton() {} ~Singleton() {} }; NAMESPACE_SIMDATA_END #endif // __SIMDATA_SINGLETON_H__ --- NEW FILE: Trace.h --- /* SimData: Data Infrastructure for Simulations * Copyright (C) 2003 Mark Rose <tm...@st...> * * This file is part of SimData. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file Trace.h * @brief Automatic callstack traces reporting on error. */ #ifndef __SIMDATA_TRACE_H__ #define __SIMDATA_TRACE_H__ #include <SimData/Namespace.h> #include <SimData/Log.h> #include <SimData/Singleton.h> #ifdef __GNUC__ # include <csignal> # include <execinfo.h> # include <exception> # include <cstdlib> #endif // __GNUC__ NAMESPACE_SIMDATA class TraceBase { typedef void (*Callback)(); logstream *_log; bool _traced; Callback _precallback, _postcallback; protected: TraceBase(): _precallback(0), _postcallback(0), _log(0), _traced(false) { } void setCallbacks_impl(Callback precallback, Callback postcallback) { _precallback = precallback; _postcallback = postcallback; } void setLog_impl(logstream &log) { _log = &log; } std::ostream &log() { if (_log) { return (*_log) << loglevel(LOG_ALL, LOG_ERROR); } else { return simdata::log() << loglevel(LOG_ALL, LOG_ERROR); } } void _preCallback() { if (_precallback != 0) _precallback(); } void _postCallback() { if (_postcallback != 0) _postcallback(); } void error(int skip, bool segv=false) { if (_traced) return; _traced = true; if (segv) { log() << "FATAL ERROR: segmentation fault." << std::endl; } _preCallback(); _backtrace(skip, segv); _postCallback(); } virtual void _backtrace(int skip, bool segv) {} }; /** Singleton callstack trace error handler. * */ class Trace: public TraceBase { #ifdef __GNUC__ virtual void _backtrace(int skip, bool segv=false) { void *trace[64]; char **messages = (char **)NULL; int i, trace_size = 0; trace_size = backtrace(trace, 64); log() << "backtrace:" << std::endl; if (0 && segv) { // XXX needed? backtrace_symbols_fd(trace, trace_size, fileno(stderr)); return; } messages = backtrace_symbols(trace, trace_size); if (messages) { for (i=skip; i<trace_size; ++i) { log() << " " << messages[i] << std::endl; } free(messages); } else { log() << " unavailable!" << std::endl; } } static void __sigsegv(int sign) { getTrace().error(3, true); abort(); } static void __sigabort(int sign) { getTrace().error(3); } #endif // __GNUC__ friend class Singleton<Trace>; static Trace &getTrace() { return Singleton<Trace>::getInstance(); } Trace(): TraceBase() {} ~Trace() {} public: /** Install a new backtrace error handler. * * @returns true if succesful. */ static bool install() { #ifdef __GNUC__ signal(SIGABRT, __sigabort); signal(SIGSEGV, __sigsegv); return true; #else // __GNUC__ return false; #endif } /** Set custom callbacks before and after the stacktrace. */ static void setCallbacks(void (*precallback)(), void (postcallback)()) { getTrace().setCallbacks_impl(precallback, postcallback); } /** Set the active log (defaults to the simdata log). */ static void setLog(logstream &log) { getTrace().setLog_impl(log); } }; NAMESPACE_SIMDATA_END #endif // __TRACE_H__ Index: Date.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/Date.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Date.h 19 Oct 2003 23:53:56 -0000 1.17 --- Date.h 24 Oct 2003 06:44:13 -0000 1.18 *************** *** 221,225 **** */ weekday_t getWeekday() const { ! return ((m_julian) % 7) + 1; } --- 221,225 ---- */ weekday_t getWeekday() const { ! return static_cast<weekday_t>((m_julian % 7) + 1); } Index: Enum.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/Enum.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Enum.h 19 Oct 2003 23:53:56 -0000 1.17 --- Enum.h 24 Oct 2003 06:44:13 -0000 1.18 *************** *** 146,150 **** int value = 0; for (int idx = 0; ss >> token; idx++) { ! std::size_t eq = token.find("="); if (eq != std::string::npos) { value = atoi(std::string(token, eq+1, std::string::npos).c_str()); --- 146,150 ---- int value = 0; for (int idx = 0; ss >> token; idx++) { ! std::string::size_type eq = token.find("="); if (eq != std::string::npos) { value = atoi(std::string(token, eq+1, std::string::npos).c_str()); Index: HashUtility.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/HashUtility.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** HashUtility.h 19 Oct 2003 23:53:56 -0000 1.19 --- HashUtility.h 24 Oct 2003 06:44:13 -0000 1.20 *************** *** 170,176 **** */ #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqint: public std::hash_compare<int const> { size_t operator ()(int const& i) const { ! return i; } bool operator()(int const& i1, int const& i2) const { --- 170,176 ---- */ #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqint: public HASH<int const> { size_t operator ()(int const& i) const { ! return static_cast<size_t>(i); } bool operator()(int const& i1, int const& i2) const { *************** *** 189,194 **** */ struct hashint { ! int operator()(int i) const { ! return i; } }; --- 189,194 ---- */ struct hashint { ! size_t operator()(int i) const { ! return static_cast<size_t>(i); } }; *************** *** 198,210 **** */ #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqstr: public std::hash_compare<char const*> ! { ! size_t operator()(char const* s ) const { ! return newhash4_cstring(s); ! } ! bool operator()(char const* s1, char const* s2) const { ! return (strcmp(s1, s2) < 0); ! } ! }; #else struct eqstr { --- 198,210 ---- */ #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqstr: public HASH<char const*> ! { ! size_t operator()(char const* s) const { ! return static_cast<size_t>(newhash4_cstring(s)); ! } ! bool operator()(char const* s1, char const* s2) const { ! return (strcmp(s1, s2) < 0); ! } ! }; #else struct eqstr { *************** *** 212,216 **** return (strcmp(s1, s2) == 0); } - }; #endif --- 212,215 ---- *************** *** 219,224 **** */ struct hasht_hash { ! uint32 operator()(hasht i1) const { ! return i1.a; } }; --- 218,223 ---- */ struct hasht_hash { ! size_t operator()(hasht i1) const { ! return static_cast<size_t>(i1.a); } }; *************** *** 226,234 **** /** hasht equality functor for hash_map. */ ! #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct hasht_eq: public std::hash_compare<hasht const> { ! size_t operator()( hasht const& i1 ) const { ! return i1.a; ! } bool operator()(hasht const& i1, hasht const& i2) const { return (i1.a < i2.a || (i1.a == i2.a && i1.b < i2.b)); --- 225,233 ---- /** hasht equality functor for hash_map. */ ! #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct hasht_eq: public HASH<hasht const> { ! size_t operator()(hasht const& i1) const { ! return static_cast<size_t>(i1.a); ! } bool operator()(hasht const& i1, hasht const& i2) const { return (i1.a < i2.a || (i1.a == i2.a && i1.b < i2.b)); *************** *** 248,253 **** struct SIMDATA_EXPORT hashstring { static HASH<const char*> h; ! int operator()(const std::string &s) const { ! return h(s.c_str()); } }; --- 247,252 ---- struct SIMDATA_EXPORT hashstring { static HASH<const char*> h; ! size_t operator()(const std::string &s) const { ! return static_cast<size_t>(h(s.c_str())); } }; *************** *** 255,261 **** /** String equality functor for hash_map. */ ! #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqstring: public std::hash_compare<std::string const> { ! size_t operator()( std::string const& a ) const { return eqstr()(a.c_str()); } --- 254,260 ---- /** String equality functor for hash_map. */ ! #if defined(_MSC_VER) && (_MSC_VER >= 1300) ! struct eqstring: public HASH<std::string const> { ! size_t operator()(std::string const& a) const { return eqstr()(a.c_str()); } Index: InterfaceRegistry.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/InterfaceRegistry.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** InterfaceRegistry.h 19 Oct 2003 23:53:56 -0000 1.23 --- InterfaceRegistry.h 24 Oct 2003 06:44:13 -0000 1.24 *************** *** 37,40 **** --- 37,41 ---- #include <SimData/TypeAdapter.h> #include <SimData/ObjectInterface.h> + #include <SimData/Singleton.h> #include <SimData/Namespace.h> #include <SimData/Exception.h> *************** *** 336,354 **** - /** Creates a single, static instance of the templated class. - */ - template <class C> - class Singleton { - public: - /** Get the one instance of the template class. - */ - static C& getInstance() { - static C __instance; - return __instance; - } - private: - Singleton() {} - ~Singleton() {} - }; /** Singleton class to store and access all ObjectInterfaces in the application. --- 337,340 ---- Index: LogStream.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/LogStream.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** LogStream.h 22 Oct 2003 01:19:46 -0000 1.11 --- LogStream.h 24 Oct 2003 06:44:13 -0000 1.12 *************** *** 138,142 **** /** overflow */ ! int overflow( int ch ); private: --- 138,142 ---- /** overflow */ ! int overflow(int ch); private: *************** *** 171,177 **** //inline logbuf::int_type inline int ! logbuf::overflow( int c ) { ! return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0); } --- 171,177 ---- //inline logbuf::int_type inline int ! logbuf::overflow(int c) { ! return logging_enabled ? sbuf->sputc(static_cast<char>(c)) : (EOF == 0 ? 1: 0); } Index: ObjectInterface.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/ObjectInterface.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** ObjectInterface.h 19 Oct 2003 23:53:56 -0000 1.27 --- ObjectInterface.h 24 Oct 2003 06:44:13 -0000 1.28 *************** *** 94,107 **** protected: void setType(BaseType &x) { type = x.typeString(); } ! void setType(double &x) { type = "builtin::double"; } ! void setType(float &x) { type = "builtin::float"; } ! void setType(unsigned int &x) { type = "builtin::uint"; } ! void setType(int &x) { type = "builtin::int"; } ! void setType(unsigned char &x) { type = "builtin::uint8"; } ! void setType(char &x) { type = "builtin::int8"; } ! void setType(unsigned short &x) { type = "builtin::uint16"; } ! void setType(short &x) { type = "builtin::int16"; } ! void setType(bool &x) { type = "builtin::bool"; } ! void setType(std::string const &x) { type = "builtin::string"; } MemberAccessorBase(): type("none") {} std::string name; --- 94,107 ---- protected: void setType(BaseType &x) { type = x.typeString(); } ! void setType(double &) { type = "builtin::double"; } ! void setType(float &) { type = "builtin::float"; } ! void setType(unsigned int &) { type = "builtin::uint"; } ! void setType(int &) { type = "builtin::int"; } ! void setType(unsigned char &) { type = "builtin::uint8"; } ! void setType(char &) { type = "builtin::int8"; } ! void setType(unsigned short &) { type = "builtin::uint16"; } ! void setType(short &) { type = "builtin::int16"; } ! void setType(bool &) { type = "builtin::bool"; } ! void setType(std::string const &) { type = "builtin::string"; } MemberAccessorBase(): type("none") {} std::string name; Index: hash_map.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/hash_map.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** hash_map.h 19 Oct 2003 23:53:56 -0000 1.10 --- hash_map.h 24 Oct 2003 06:44:13 -0000 1.11 *************** *** 28,32 **** #define __SIMDATA_HASH_MAP_H__ ! #if defined(__GNUC__) || defined(__INTEL_COMPILER) #if __GNUC__ >= 3 #include <ext/hash_map> --- 28,32 ---- #define __SIMDATA_HASH_MAP_H__ ! #if defined(__GNUC__) //|| defined(__INTEL_COMPILER) #if __GNUC__ >= 3 #include <ext/hash_map> *************** *** 45,49 **** #else #ifdef _MSC_VER ! #if (_MSC_VER <= 1200) && defined(_STLP_WIN32) #include <hash_map> #define HASH_MAP std::hash_map --- 45,53 ---- #else #ifdef _MSC_VER ! #if defined(_STLPORT) ! #include <hash_map> ! #define HASH_MAP std::hash_map ! #define HASH std::hash ! #elif ((_MSC_VER <= 1200) && defined(_STLP_WIN32)) #include <hash_map> #define HASH_MAP std::hash_map |