From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 31 Aug 2007 13:32:40 -0000 Subject: [Cluster-devel] conga/ricci/include APIerror.h Except.h File.h ... Message-ID: <20070831133240.32480.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2007-08-31 13:32:37 Modified files: ricci/include : APIerror.h Except.h File.h Logger.h Module.h Mutex.h Network.h Random.h Socket.h String.h Thread.h Time.h Variable.h XML.h XML_tags.h array_auto_ptr.h counting_auto_ptr.cpp counting_auto_ptr.h executils.h executils_test.h shred_allocator.h utils.h Log message: More cleanup Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/APIerror.h.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Except.h.diff?cvsroot=cluster&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/File.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Logger.h.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Module.h.diff?cvsroot=cluster&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Mutex.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Network.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Random.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Socket.h.diff?cvsroot=cluster&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/String.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Thread.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Time.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Variable.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/XML.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/XML_tags.h.diff?cvsroot=cluster&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/array_auto_ptr.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.cpp.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/executils.h.diff?cvsroot=cluster&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/executils_test.h.diff?cvsroot=cluster&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/shred_allocator.h.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/utils.h.diff?cvsroot=cluster&r1=1.6&r2=1.7 --- conga/ricci/include/APIerror.h 2006/08/10 22:53:07 1.2 +++ conga/ricci/include/APIerror.h 2007/08/31 13:32:36 1.3 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2006 + Copyright Red Hat, Inc. 2006-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,20 +21,17 @@ */ -#ifndef APIerror_h -#define APIerror_h +#ifndef __CONGA_APIerror_h +#define __CONGA_APIerror_h - -class APIerror +class APIerror { - public: - APIerror() : msg("") {} - APIerror(const String& msg) : msg(msg) {} - virtual ~APIerror() {} - - const String msg; - -}; + public: + APIerror() : msg("") {} + APIerror(const String& msg) : msg(msg) {} + virtual ~APIerror() {} + const String msg; +}; -#endif // APIerror_h +#endif --- conga/ricci/include/Except.h 2006/08/10 22:53:07 1.3 +++ conga/ricci/include/Except.h 2007/08/31 13:32:36 1.4 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,30 +21,27 @@ */ -#ifndef Except_h -#define Except_h +#ifndef __CONGA_Except_h +#define __CONGA_Except_h #include "String.h" - class Except { - public: - virtual ~Except(); - - long long code() const; - String description() const; - - static const long long generic_error = -1; - - protected: - Except(long long error_code, - const String& msg); - - private: - long long _code; - String _msg; -}; + public: + virtual ~Except(); + + long long code() const; + String description() const; + static const long long generic_error = -1; + + protected: + Except(long long error_code, const String& msg); + + private: + long long _code; + String _msg; +}; -#endif // Except_h +#endif // Except_h --- conga/ricci/include/File.h 2006/10/23 18:43:35 1.1 +++ conga/ricci/include/File.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2006 + Copyright Red Hat, Inc. 2006-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,8 +21,8 @@ */ -#ifndef File_h -#define File_h +#ifndef __CONGA_File_h +#define __CONGA_File_h #include "String.h" #include "counting_auto_ptr.h" @@ -30,55 +30,48 @@ class File_pimpl { - public: - File_pimpl(void*, bool&); - virtual ~File_pimpl(); - void* const fs; - private: - File_pimpl(const File_pimpl&); - File_pimpl& operator=(const File_pimpl&); + public: + File_pimpl(void*, bool&); + virtual ~File_pimpl(); + void* const fs; + private: + File_pimpl(const File_pimpl&); + File_pimpl& operator=(const File_pimpl&); }; class File { - public: - - // throw if non-existant - static File open(const String& filepath, - bool rw=false); - // same as open, but create if nonexistant - static File create(const String& filepath, - bool truncate=false); - virtual ~File(); - - String path() const; - long size() const; - - String read() const; // return content - - File& append(const String& data); // append data to the end of file - - String replace(const String& data); // replace content with data, return old content - - void shred(); - void unlink(); - - operator const String () const; - - private: - File(counting_auto_ptr, - const String& path, - bool writable); - - counting_auto_ptr _mutex; - counting_auto_ptr _pimpl; - const String _path; - const bool _writable; - - void check_failed() const; - -}; + public: + // throw if non-existent + static File open(const String& filepath, bool rw=false); + // same as open, but create if nonexistent + static File create(const String& filepath, bool truncate=false); + virtual ~File(); + + String path() const; + long size() const; + + String read() const; // return content + + File& append(const String& data); // append data to the end of file + + // replace content with data, return old content + String replace(const String& data); + void shred(); + void unlink(); + + operator const String () const; + + private: + File(counting_auto_ptr, const String& path, bool writable); + counting_auto_ptr _mutex; + counting_auto_ptr _pimpl; + const String _path; + const bool _writable; + + void check_failed() const; +}; -#endif // File_h +#endif --- conga/ricci/include/Logger.h 2006/08/10 22:53:07 1.2 +++ conga/ricci/include/Logger.h 2007/08/31 13:32:36 1.3 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,58 +21,54 @@ */ -#ifndef Logger_h -#define Logger_h +#ifndef __CONGA_Logger_h +#define __CONGA_Logger_h #include "counting_auto_ptr.h" #include "String.h" - - -enum LogLevel {LogNone = 0, - LogBasic = 1, - LogMonitor = 2, - LogSocket = 4, - LogCommunicator = 8, - LogTransfer = 16, - LogExit = 32, - LogThread = 64, - LogTime = 128, - LogExecute = 256, - LogAll = ~0 }; - +enum LogLevel { + LogNone = 0, + LogBasic = 1, + LogMonitor = 2, + LogSocket = 4, + LogCommunicator = 8, + LogTransfer = 16, + LogExit = 32, + LogThread = 64, + LogTime = 128, + LogExecute = 256, + LogAll = ~0 +}; class Logger { - public: - Logger(); - Logger(const String& filepath, const String& domain, LogLevel level); - Logger(int fd, const String& domain, LogLevel level); - virtual ~Logger(); - - void log(const String& msg, LogLevel level=LogBasic); - void log_sigsafe(const char* msg, LogLevel level=LogBasic); - void operator<< (const String& msg) { log(msg); } - - private: - int _fd; - char* _domain_c; - int _level; - - void close_fd(); - - Logger(const Logger&); - Logger& operator= (const Logger&); -}; // class Logger - - + public: + Logger(); + Logger(const String& filepath, const String& domain, LogLevel level); + Logger(int fd, const String& domain, LogLevel level); + virtual ~Logger(); + + void log(const String& msg, LogLevel level=LogBasic); + void log_sigsafe(const char* msg, LogLevel level=LogBasic); + void operator<< (const String& msg) { log(msg); } + + private: + int _fd; + char *_domain_c; + int _level; + + void close_fd(); + + Logger(const Logger&); + Logger& operator= (const Logger&); +}; + // helper functions String operator+ (const String&, int); String operator+ (int, const String&); void log(const String& msg, LogLevel level=LogBasic); void log_sigsafe(const char* msg, LogLevel level=LogBasic); void set_logger(counting_auto_ptr); - - -#endif // Logger_h +#endif --- conga/ricci/include/Module.h 2006/08/15 04:15:53 1.3 +++ conga/ricci/include/Module.h 2007/08/31 13:32:36 1.4 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2006 + Copyright Red Hat, Inc. 2006-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,8 +21,8 @@ */ -#ifndef Module_h -#define Module_h +#ifndef __CONGA_Module_h +#define __CONGA_Module_h #include "XML.h" #include "Variable.h" @@ -32,35 +32,26 @@ #include #include - // name->variable map -typedef std::map VarMap; +typedef std::map VarMap; // name->function map -typedef std::map FcnMap; +typedef std::map FcnMap; // api->name->function map -typedef std::map ApiFcnMap; - +typedef std::map ApiFcnMap; class Module { - public: - virtual ~Module(); - - virtual XMLObject process(const XMLObject& request); - - protected: - Module(const ApiFcnMap& api_fcns); - -}; // class Module - - -int -stdin_out_module_driver(Module& module, - int argc, - char** argv); + public: + virtual ~Module(); + virtual XMLObject process(const XMLObject& request); + + protected: + Module(const ApiFcnMap& api_fcns); + +}; +int stdin_out_module_driver(Module& module, int argc, char **argv); -#endif // Module_h +#endif --- conga/ricci/include/Mutex.h 2006/03/06 21:48:04 1.1 +++ conga/ricci/include/Mutex.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,53 +21,59 @@ */ -#ifndef Mutex_h -#define Mutex_h +#ifndef __CONGA_Mutex_h +#define __CONGA_Mutex_h #include - class Mutex { - public: - Mutex() - { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutex_init(&_mutex, &attr); - pthread_mutexattr_destroy(&attr); - } - virtual ~Mutex() - { pthread_mutex_destroy(&_mutex); } - - void lock() - { pthread_mutex_lock(&_mutex); } - void unlock() - { pthread_mutex_unlock(&_mutex); } - - private: - pthread_mutex_t _mutex; - - Mutex(const Mutex&); - Mutex& operator= (const Mutex&); -}; // class Mutex - + public: + Mutex() { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&_mutex, &attr); + pthread_mutexattr_destroy(&attr); + } + + virtual ~Mutex() { + pthread_mutex_destroy(&_mutex); + } + + void lock() { + pthread_mutex_lock(&_mutex); + } + + void unlock() { + pthread_mutex_unlock(&_mutex); + } + + private: + pthread_mutex_t _mutex; + Mutex(const Mutex&); + Mutex& operator= (const Mutex&); +}; class MutexLocker { - public: - MutexLocker(Mutex& m) : - _mutex(m) { _mutex.lock(); } - virtual ~MutexLocker() { _mutex.unlock(); } - - private: - Mutex& _mutex; - - MutexLocker(const MutexLocker&); - MutexLocker& operator= (const MutexLocker&); -}; // class MutexLocker - + public: + MutexLocker(Mutex& m) : + _mutex(m) + { + _mutex.lock(); + } + + virtual ~MutexLocker() { + _mutex.unlock(); + } + + private: + Mutex& _mutex; + + MutexLocker(const MutexLocker&); + MutexLocker& operator= (const MutexLocker&); +}; -#endif // Mutex_h +#endif --- conga/ricci/include/Network.h 2007/03/23 17:25:13 1.1 +++ conga/ricci/include/Network.h 2007/08/31 13:32:36 1.2 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -30,25 +30,22 @@ #include - class Network { - public: - static std::vector name2IP(const String& hostname); - static String localhost(); - - - class Hostent - { - public: - struct hostent ent; - char data[4*1024 - sizeof(struct hostent)]; - struct hostent* operator->() { return &ent; } - struct hostent& operator*() { return ent; } - }; - static counting_auto_ptr getHostByName(const String& hostname); - -}; + public: + static std::vector name2IP(const String& hostname); + static String localhost(); -#endif // Conga_Network_h + class Hostent + { + public: + struct hostent ent; + char data[4*1024 - sizeof(struct hostent)]; + struct hostent* operator->() { return &ent; } + struct hostent& operator*() { return ent; } + }; + static counting_auto_ptr getHostByName(const String& hostname); +}; + +#endif --- conga/ricci/include/Random.h 2006/03/23 16:29:37 1.1 +++ conga/ricci/include/Random.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,11 +21,9 @@ */ -#ifndef Random_h -#define Random_h - +#ifndef __CONGA_Random_h +#define __CONGA_Random_h int random_generator(int min, int max); - -#endif // Random_h +#endif --- conga/ricci/include/Socket.h 2007/03/23 17:25:13 1.5 +++ conga/ricci/include/Socket.h 2007/08/31 13:32:36 1.6 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,8 +21,8 @@ */ -#ifndef Socket_h -#define Socket_h +#ifndef __CONGA_SOCKET_H +#define __CONGA_SOCKET_H #include "counting_auto_ptr.h" @@ -33,90 +33,84 @@ // NOT THREAD SAFE // provide external locking - class Socket { - public: - Socket(const Socket&); - virtual Socket& operator= (const Socket&); - virtual ~Socket(); - - virtual bool operator== (const Socket&); - virtual bool server() = 0; - - int get_sock(); - bool valid() { return _sock != -1; } - - bool nonblocking(); // return whether O_NONBLOCK is set - bool nonblocking(bool mode); // set O_NONBLOCK, return old state - - protected: - Socket(int sock); // takes ownership of sock - int _sock; - void close(); - counting_auto_ptr _counter; - - void poll(bool& read, bool& write, int timeout); // milliseconds - - private: - void decrease_counter(); -}; // class Socket + public: + Socket(const Socket&); + virtual Socket& operator= (const Socket&); + virtual ~Socket(); + + virtual bool operator== (const Socket&); + virtual bool server() = 0; + + int get_sock(); + bool valid() { return _sock != -1; } + + bool nonblocking(); // return whether O_NONBLOCK is set + bool nonblocking(bool mode); // set O_NONBLOCK, return old state + + protected: + Socket(int sock); // takes ownership of sock + int _sock; + void close(); + counting_auto_ptr _counter; + + void poll(bool& read, bool& write, int timeout); // milliseconds + + private: + void decrease_counter(); +}; class ServerSocket; class ClientSocket : public Socket { - public: - ClientSocket(); - ClientSocket(const String& sock_path); // UNIX socket - ClientSocket(const String& hostname, unsigned short port, - unsigned int timeout_ms=0 /* 0 - standard blocking behavior - >0 - timeout - */ ); // TCP socket - ClientSocket(const ClientSocket&); - virtual ClientSocket& operator= (const ClientSocket&); - virtual ~ClientSocket(); - - virtual String recv(); - virtual String recv(int timeout); - virtual String send(const String& msg); // return what is left to send - virtual String send(const String& msg, int timeout); - - virtual void ready(bool& recv, bool& send, int timeout); - - virtual bool server() { return false; } - - virtual bool connected_to(const String& hostname); - - protected: - u_int32_t _addr; // address in network byte order - - ClientSocket(int sock, u_int32_t addr=0); // takes ownership of sock - friend class ServerSocket; -}; // ClientSocket + public: + ClientSocket(); + ClientSocket(const String& sock_path); // UNIX socket + ClientSocket( const String& hostname, + unsigned short port, + unsigned int timeout_ms=0); + ClientSocket(const ClientSocket&); + virtual ClientSocket& operator= (const ClientSocket&); + virtual ~ClientSocket(); + + virtual String recv(); + virtual String recv(int timeout); + virtual String send(const String& msg); // return what is left to send + virtual String send(const String& msg, int timeout); + + virtual void ready(bool& recv, bool& send, int timeout); + virtual bool server() { return false; } + virtual bool connected_to(const String& hostname); + + protected: + u_int32_t _addr; // address in network byte order + + ClientSocket(int sock, u_int32_t addr=0); // takes ownership of sock + friend class ServerSocket; +}; class ServerSocket : public Socket { - public: - ServerSocket(const String& sock_path); // UNIX socket - ServerSocket(unsigned short port); // TCP socket - ServerSocket(const ServerSocket&); - virtual ServerSocket& operator= (const ServerSocket&); - virtual ~ServerSocket(); - - ClientSocket accept(); - - virtual bool ready(int timeout); - - virtual bool server() { return true; } - - private: - bool _unix_sock; - String _sock_path; - -}; // ServerSocket + public: + ServerSocket(const String& sock_path); // UNIX socket + ServerSocket(unsigned short port); // TCP socket + ServerSocket(const ServerSocket&); + virtual ServerSocket& operator= (const ServerSocket&); + virtual ~ServerSocket(); + + ClientSocket accept(); + + virtual bool ready(int timeout); + + virtual bool server() { return true; } + private: + bool _unix_sock; + String _sock_path; +}; -#endif // Socket_h +#endif --- conga/ricci/include/String.h 2006/08/10 23:01:58 1.1 +++ conga/ricci/include/String.h 2007/08/31 13:32:36 1.2 @@ -1,17 +1,11 @@ - - -#ifndef String_h -#define String_h - +#ifndef __CONGA_STRING_H +#define __CONGA_STRING_H #include #include "shred_allocator.h" +typedef std::basic_string, + shred_allocator > String; -typedef std::basic_string, - shred_allocator > String; - - - -#endif // String_h +#endif --- conga/ricci/include/Thread.h 2006/03/06 21:48:04 1.1 +++ conga/ricci/include/Thread.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,50 +13,46 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Author: Stanko Kupcevic */ - -#ifndef Thread_h -#define Thread_h +#ifndef __CONGA_Thread_h +#define __CONGA_Thread_h #include #include "Mutex.h" - - class Thread { - public: - Thread(); - virtual ~Thread(); - - // not to be called from run() - virtual void start(); - virtual void stop(); - virtual bool running(); - - protected: - virtual bool shouldStop(); // kids, return from run() if true, check it often - virtual void run() = 0; // run in new thread - - private: - pthread_t _thread; - - bool _stop; - Mutex _stop_mutex; - - bool _running; - Mutex _main_mutex; - - Thread(const Thread&); - Thread& operator= (const Thread&); - friend void* start_thread(void*); -}; // class Thread + public: + Thread(); + virtual ~Thread(); + + // not to be called from run() + virtual void start(); + virtual void stop(); + virtual bool running(); + + protected: + // kids, return from run() if true, check it often + virtual bool shouldStop(); + virtual void run() = 0; // run in new thread + + private: + bool _stop; + bool _running; + pthread_t _thread; + Mutex _stop_mutex; + Mutex _main_mutex; + + Thread(const Thread&); + Thread& operator= (const Thread&); + friend void* start_thread(void*); +}; -#endif // Thread_h +#endif --- conga/ricci/include/Time.h 2006/08/10 22:53:07 1.4 +++ conga/ricci/include/Time.h 2007/08/31 13:32:36 1.5 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,12 +21,11 @@ */ -#ifndef Time_h -#define Time_h +#ifndef __CONGA_TIME_H +#define __CONGA_TIME_H #include "String.h" - // number of seconds since Epoch unsigned int time_sec(); @@ -35,10 +34,10 @@ // sleep num milliseconds void sleep_mil(unsigned char num); + // sleep num seconds void sleep_sec(unsigned char num); String time_formated(); - -#endif // Time_h +#endif --- conga/ricci/include/Variable.h 2006/09/26 01:04:20 1.4 +++ conga/ricci/include/Variable.h 2007/08/31 13:32:36 1.5 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,226 +13,194 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Author: Stanko Kupcevic */ - -#ifndef Variable_h -#define Variable_h +#ifndef __CONGA_VARIABLE_H +#define __CONGA_VARIABLE_H #include "String.h" #include #include "XML.h" - - -enum VarType {Integer = 1, - IntSel = 2, // integer selector - Boolean = 3, - StringVar = 4, - StrSel = 5, // string selector - XMLVar = 6, - ListInt = 7, - ListStr = 8, - ListXML = 9}; - - - - +enum VarType { + Integer = 1, + IntSel = 2, // integer selector + Boolean = 3, + StringVar = 4, + StrSel = 5, // string selector + XMLVar = 6, + ListInt = 7, + ListStr = 8, + ListXML = 9 +}; class Validator { - public: - Validator(); // always valid - - // integer - Validator(long long min, - long long max, - long long step); - - // integer selector - Validator(const std::list& valid_values); - - // string - Validator(long long min_length, - long long max_length, - const String& illegal_chars, - const std::list& reserved_words); - - // string selector - Validator(const std::list& valid_words); - - virtual ~Validator(); - - - bool validate(long long value) const; - bool validate(const String& value) const; - bool validate(bool value) const; - bool validate(const XMLObject& value) const; - bool validate(const std::list& value) const; - bool validate(const std::list& value) const; - bool validate(const std::list& value) const; - - - void export_params(XMLObject& xml) const; - - - private: - bool _always_valid; - - bool _integer; - long long _min; - long long _max; - long long _step; - - bool _int_sel; - std::list _valid_ints; - - bool _string; - long long _min_length; - long long _max_length; - String _illegal_chars; - std::list _reserved_words; - - bool _string_sel; - std::list _valid_words; - -}; // class Validator - - - + public: + Validator(); // always valid + // integer + Validator(long long min, long long max, long long step); + // integer selector + Validator(const std::list& valid_values); + // string + Validator( long long min_length, + long long max_length, + const String& illegal_chars, + const std::list& reserved_words); + + // string selector + Validator(const std::list& valid_words); + + virtual ~Validator(); + + bool validate(long long value) const; + bool validate(const String& value) const; + bool validate(bool value) const; + bool validate(const XMLObject& value) const; + bool validate(const std::list& value) const; + bool validate(const std::list& value) const; + bool validate(const std::list& value) const; + + void export_params(XMLObject& xml) const; + + private: + bool _always_valid; + bool _integer; + long long _min; + long long _max; + long long _step; + bool _int_sel; + std::list _valid_ints; + bool _string; + long long _min_length; + long long _max_length; + String _illegal_chars; + std::list _reserved_words; + bool _string_sel; + std::list _valid_words; +}; class Variable { - public: - // integer - Variable(const String& name, - long long value); - Variable(const String& name, - long long value, - long long min, - long long max, - long long step); - - // integer selector - Variable(const String& name, - long long value, - const std::list& valid_values); - - // integer list - Variable(const String& name, - const std::list& value, - bool mutabl=false); - - - // boolean - Variable(const String& name, - bool value, - bool mutabl=false); - - // string - Variable(const String& name, - const String& value); - Variable(const String& name, - const String& value, - long long min_length, - long long max_length, - const String& illegal_chars, - const std::list& reserved_words); - - // string selector - Variable(const String& name, - const String& value, - const std::list& valid_words); - - // string list - Variable(const String& name, - const std::list& value, - bool mutabl=false); - - // xml - Variable(const String& name, - const XMLObject& value); - - // xml list - Variable(const String& name, - const std::list& value); - - - Variable(const XMLObject& xml); - - virtual ~Variable(); - - - String name() const { return _name; } - VarType type() const { return _type; } - bool mutabl() const { return _mutable; } - void mutabl(bool mutabl) { _mutable = mutabl; } - - bool validate() const; - bool validate(const Variable& var) const; // validate var against self - - bool equal(const Variable& var) const; - - XMLObject xml() const; - - - void set_conditional_bool_if(const String& bool_name); - String get_conditional_bool_if() const - { return _cond_bool_if; } - - void set_conditional_bool_ifnot(const String& bool_name); - String get_conditional_bool_ifnot() const - { return _cond_bool_ifnot; } - - - // values getters and setters - - void set_value(long long value); - void set_value(bool value); - void set_value(const String& value); - void set_value(const XMLObject& value); - void set_value(const std::list& value); - void set_value(const std::list& value); - void set_value(const std::list& value); - - long long get_int() const; - bool get_bool() const; - String get_string() const; - XMLObject get_XML() const; - std::list get_list_int() const; - std::list get_list_str() const; - std::list get_list_XML() const; - - - - private: - String _name; - VarType _type; - - long long _val_int; - bool _val_bool; - String _val_str; - XMLObject _val_xml; - std::list _val_list_int; - std::list _val_list_str; - std::list _val_list_XML; - - bool _mutable; - - String _cond_bool_if; - String _cond_bool_ifnot; - - Validator _validator; - -}; // class Variable + public: + // integer + Variable(const String& name, long long value); + Variable( const String& name, + long long value, + long long min, + long long max, + long long step); + + // integer selector + Variable( const String& name, + long long value, + const std::list& valid_values); + + // integer list + Variable( const String& name, + const std::list& value, + bool mutabl=false); + + + // boolean + Variable(const String& name, bool value, bool mutabl=false); + + // string + Variable(const String& name, const String& value); + Variable( const String& name, + const String& value, + long long min_length, + long long max_length, + const String& illegal_chars, + const std::list& reserved_words); + + // string selector + Variable( const String& name, + const String& value, + const std::list& valid_words); + + // string list + Variable( const String& name, + const std::list& value, + bool mutabl=false); + + // xml + Variable(const String& name, const XMLObject& value); + + // xml list + Variable(const String& name, const std::list& value); + + Variable(const XMLObject& xml); + + virtual ~Variable(); + + String name() const { return _name; } + VarType type() const { return _type; } + bool mutabl() const { return _mutable; } + void mutabl(bool mutabl) { _mutable = mutabl; } + + bool validate() const; + bool validate(const Variable& var) const; // validate var against self + + bool equal(const Variable& var) const; + + XMLObject xml() const; + + void set_conditional_bool_if(const String& bool_name); + String get_conditional_bool_if() const { + return _cond_bool_if; + } + + void set_conditional_bool_ifnot(const String& bool_name); + String get_conditional_bool_ifnot() const { + return _cond_bool_ifnot; + } + + // values getters and setters + + void set_value(long long value); + void set_value(bool value); + void set_value(const String& value); + void set_value(const XMLObject& value); + void set_value(const std::list& value); + void set_value(const std::list& value); + void set_value(const std::list& value); + + long long get_int() const; + bool get_bool() const; + String get_string() const; + XMLObject get_XML() const; + std::list get_list_int() const; + std::list get_list_str() const; + std::list get_list_XML() const; + + private: + String _name; + VarType _type; + + long long _val_int; + bool _val_bool; + String _val_str; + XMLObject _val_xml; + std::list _val_list_int; + std::list _val_list_str; + std::list _val_list_XML; + + bool _mutable; + + String _cond_bool_if; + String _cond_bool_ifnot; + + Validator _validator; +}; -#endif // Variable_h +#endif --- conga/ricci/include/XML.h 2006/09/26 00:54:26 1.4 +++ conga/ricci/include/XML.h 2007/08/31 13:32:36 1.5 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,46 +21,52 @@ */ -#ifndef XML_h -#define XML_h +#ifndef __CONGA_XML_H +#define __CONGA_XML_H #include "String.h" #include #include - class XMLObject { - public: - XMLObject(const String& elem_name = "TagName"); - virtual ~XMLObject(); - - String tag() const - { return _tag; }; - - // attributes - bool has_attr(const String& attr_name) const; - String set_attr(const String& attr_name, - const String& value); // return old value - String get_attr(const String& attr_name) const; - const std::map& attrs() const - { return _attrs; } - - // kids - XMLObject& add_child(const XMLObject& child); - bool remove_child(const XMLObject& child); - const std::list& children() const - { return _kids; } - - bool operator== (const XMLObject&) const; - - private: - String _tag; - std::list _kids; - std::map _attrs; - void generate_xml(String& xml, const String& indent) const; - friend String generateXML(const XMLObject& obj); + public: + XMLObject(const String& elem_name = "TagName"); + virtual ~XMLObject(); + + String tag() const { + return _tag; + }; + + // attributes + bool has_attr(const String& attr_name) const; + + // return old value + String set_attr(const String& attr_name, const String& value); + + String get_attr(const String& attr_name) const; + + const std::map& attrs() const { + return _attrs; + } + + // kids + XMLObject& add_child(const XMLObject& child); + bool remove_child(const XMLObject& child); + + const std::list& children() const { + return _kids; + } + + bool operator== (const XMLObject&) const; + + private: + String _tag; + std::list _kids; + std::map _attrs; + void generate_xml(String& xml, const String& indent) const; + friend String generateXML(const XMLObject& obj); }; @@ -68,5 +74,4 @@ XMLObject parseXML(const String& xml); String generateXML(const XMLObject& obj); - -#endif // XML_h +#endif --- conga/ricci/include/XML_tags.h 2006/08/10 22:53:07 1.4 +++ conga/ricci/include/XML_tags.h 2007/08/31 13:32:36 1.5 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,42 +21,35 @@ */ -#ifndef XML_tags_h -#define XML_tags_h +#ifndef __CONGA_XML_TAGS_H +#define __CONGA_XML_TAGS_H #include "String.h" - - // XML tags for various objects - // ### Variable ### -#define VARIABLE_TAG String("var") - -#define VARIABLE_INT String("int") -#define VARIABLE_INT_SEL String("int_select") -#define VARIABLE_BOOL String("boolean") -#define VARIABLE_STR String("string") -#define VARIABLE_STR_SEL String("string_select") -#define VARIABLE_XML String("xml") -#define VARIABLE_LIST_STR String("list_str") -#define VARIABLE_LIST_INT String("list_int") -#define VARIABLE_LIST_XML String("list_xml") -#define VARIABLE_LISTENTRY String("listentry") - - - -#define REQUEST_TAG String("request") -#define RESPONSE_TAG String("response") -#define SEQUENCE_TAG String("sequence") - -#define FUNC_CALL_TAG String("function_call") -#define FUNC_RESPONSE_TAG String("function_response") +#define VARIABLE_TAG String("var") -#define MOD_VERSION_TAG String("API_version") +#define VARIABLE_INT String("int") +#define VARIABLE_INT_SEL String("int_select") +#define VARIABLE_BOOL String("boolean") +#define VARIABLE_STR String("string") +#define VARIABLE_STR_SEL String("string_select") +#define VARIABLE_XML String("xml") +#define VARIABLE_LIST_STR String("list_str") +#define VARIABLE_LIST_INT String("list_int") +#define VARIABLE_LIST_XML String("list_xml") +#define VARIABLE_LISTENTRY String("listentry") + +#define REQUEST_TAG String("request") +#define RESPONSE_TAG String("response") +#define SEQUENCE_TAG String("sequence") +#define FUNC_CALL_TAG String("function_call") +#define FUNC_RESPONSE_TAG String("function_response") +#define MOD_VERSION_TAG String("API_version") -#endif // XML_tags_h +#endif --- conga/ricci/include/array_auto_ptr.h 2006/03/27 23:15:30 1.1 +++ conga/ricci/include/array_auto_ptr.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -24,23 +24,20 @@ #ifndef array_auto_ptr_h #define array_auto_ptr_h - template class array_auto_ptr { - public: - array_auto_ptr(T* array) : _arr(array) {} - virtual ~array_auto_ptr() { delete[] _arr; } - - T& operator [] (unsigned int i) { return _arr[i]; } - T* get() { return _arr; } - - private: - T* _arr; - - array_auto_ptr(const array_auto_ptr&); - array_auto_ptr& operator= (const array_auto_ptr&); -}; // class array_auto_ptr - + public: + array_auto_ptr(T* array) : _arr(array) {} + virtual ~array_auto_ptr() { delete[] _arr; } + + T& operator [] (unsigned int i) { return _arr[i]; } + T* get() { return _arr; } + + private: + T* _arr; + array_auto_ptr(const array_auto_ptr&); + array_auto_ptr& operator= (const array_auto_ptr&); +}; -#endif // array_auto_ptr_h +#endif --- conga/ricci/include/counting_auto_ptr.cpp 2006/03/06 21:48:04 1.1 +++ conga/ricci/include/counting_auto_ptr.cpp 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -25,70 +25,71 @@ template -counting_auto_ptr::counting_auto_ptr(X* ptr) : - _ptr(ptr) +counting_auto_ptr::counting_auto_ptr(X* ptr) : + _ptr(ptr) { - try { - _counter = new int(1); - } catch ( ... ) { - delete _ptr; - throw; - } - - try { - _mutex = new Mutex(); - } catch ( ... ) { - delete _ptr; - delete _counter; - throw; - } + try { + _counter = new int(1); + } catch ( ... ) { + delete _ptr; + throw; + } + + try { + _mutex = new Mutex(); + } catch ( ... ) { + delete _ptr; + delete _counter; + throw; + } }; template counting_auto_ptr::counting_auto_ptr(const counting_auto_ptr& o) { - MutexLocker l(*(o._mutex)); - _ptr = o._ptr; - _mutex = o._mutex; - _counter = o._counter; - (*_counter)++; + MutexLocker l(*(o._mutex)); + _ptr = o._ptr; + _mutex = o._mutex; + _counter = o._counter; + (*_counter)++; }; -template +template counting_auto_ptr& counting_auto_ptr::operator= (const counting_auto_ptr& o) { - if (&o != this) { - decrease_counter(); - MutexLocker l(*(o._mutex)); - _ptr = o._ptr; - _mutex = o._mutex; - _counter = o._counter; - (*_counter)++; - } - return *this; + if (&o != this) { + decrease_counter(); + MutexLocker l(*(o._mutex)); + _ptr = o._ptr; + _mutex = o._mutex; + _counter = o._counter; + (*_counter)++; + } + return *this; }; template counting_auto_ptr::~counting_auto_ptr() { - decrease_counter(); + decrease_counter(); }; template -void +void counting_auto_ptr::decrease_counter() { - bool last = false; - { - MutexLocker l(*_mutex); - last = (--(*_counter) == 0); - } - if (last) { - delete _counter; - delete _ptr; - delete _mutex; - } + bool last = false; + { + MutexLocker l(*_mutex); + last = (--(*_counter) == 0); + } + + if (last) { + delete _counter; + delete _ptr; + delete _mutex; + } }; @@ -96,20 +97,19 @@ X& counting_auto_ptr::operator*() const { - return *_ptr; + return *_ptr; }; template X* counting_auto_ptr::operator->() const { - return _ptr; + return _ptr; }; template X* counting_auto_ptr::get() const { - return _ptr; + return _ptr; }; - --- conga/ricci/include/counting_auto_ptr.h 2006/03/06 21:48:04 1.1 +++ conga/ricci/include/counting_auto_ptr.h 2007/08/31 13:32:36 1.2 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -26,36 +26,31 @@ #include "Mutex.h" - - template class counting_auto_ptr { - public: - explicit counting_auto_ptr(X* ptr = 0); - counting_auto_ptr(const counting_auto_ptr&); - counting_auto_ptr& operator= (const counting_auto_ptr&); - virtual ~counting_auto_ptr(); - - X& operator*() const; - X* operator->() const; - - bool operator== (const counting_auto_ptr& a) const - { return _ptr == a._ptr; } - - X* get() const; - - private: - X* _ptr; - - Mutex* _mutex; - int* _counter; - - void decrease_counter(); - + public: + explicit counting_auto_ptr(X* ptr = 0); + counting_auto_ptr(const counting_auto_ptr&); + counting_auto_ptr& operator= (const counting_auto_ptr&); + virtual ~counting_auto_ptr(); + + X& operator*() const; + X* operator->() const; + + bool operator== (const counting_auto_ptr& a) const { + return _ptr == a._ptr; + } + + X* get() const; + + private: + X* _ptr; + Mutex* _mutex; + int* _counter; + void decrease_counter(); }; #include "counting_auto_ptr.cpp" - #endif --- conga/ricci/include/executils.h 2006/08/10 22:53:07 1.3 +++ conga/ricci/include/executils.h 2007/08/31 13:32:36 1.4 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,22 +21,23 @@ */ -#ifndef executils_h -#define executils_h +#ifndef __CONGA_executils_h +#define __CONGA_executils_h #include "String.h" #include -// return 0 on success, non-zero on failure -int execute(const String& path, - const std::vector& args, - String& out, - String& err, - int& status, - int timeout=-1 /* milliseconds, - kill child after timeout has elapsed, - negative for no timeout */ ); - +/* +** return 0 on success, non-zero on failure +** Kill the child process after @timeout ms has elapsed, +** if @timeout is negative, there's no no timeout +*/ +int execute(const String& path, + const std::vector& args, + String& out, + String& err, + int& status, + int timeout=-1); #endif // executils_h --- conga/ricci/include/executils_test.h 2006/03/06 21:48:04 1.1 +++ conga/ricci/include/executils_test.h 2007/08/31 13:32:36 1.2 @@ -9,10 +9,10 @@ class Killer : public ClusterMonitoring::Thread { public: - + protected: virtual void run(); - + }; --- conga/ricci/include/shred_allocator.h 2006/08/15 04:15:53 1.2 +++ conga/ricci/include/shred_allocator.h 2007/08/31 13:32:36 1.3 @@ -40,9 +40,9 @@ void shred(_Tp* __p, size_t n) { - size_t size = sizeof(_Tp) / sizeof(char) * n; + size_t size = sizeof(_Tp) / sizeof(char) * n; if (size && __p) - for (char *ptr = (char*) __p; + for (char *ptr = (char*) __p; ptr < ((char*) __p) + size; ptr++) *ptr = 'o'; @@ -60,26 +60,26 @@ typedef _Tp& reference; typedef const _Tp& const_reference; typedef _Tp value_type; - + template struct rebind { typedef shred_allocator<_Tp1> other; }; - + shred_allocator() throw() { } - + shred_allocator(const shred_allocator&) throw() { } - + template shred_allocator(const shred_allocator<_Tp1>&) throw() { } - + ~shred_allocator() throw() { } - + pointer address(reference __x) const { return &__x; } - + const_pointer address(const_reference __x) const { return &__x; } - + // NB: __n is permitted to be 0. The C++ standard says nothing // about what the return value is when __n == 0. pointer @@ -90,26 +90,26 @@ throw std::bad_alloc(); return __ret; } - + // __p is not permitted to be a null pointer. void deallocate(pointer __p, size_type n) - { + { shred(__p, n); free(static_cast(__p)); } - + size_type - max_size() const throw() + max_size() const throw() { return size_t(-1) / sizeof(_Tp); } - + // _GLIBCXX_RESOLVE_LIB_DEFECTS // 402. wrong new expression in [some_] allocator::construct - void - construct(pointer __p, const _Tp& __val) + void + construct(pointer __p, const _Tp& __val) { ::new(__p) _Tp(__val); } - - void + + void destroy(pointer __p) { __p->~_Tp(); } }; --- conga/ricci/include/utils.h 2006/10/06 03:10:13 1.6 +++ conga/ricci/include/utils.h 2007/08/31 13:32:36 1.7 @@ -1,5 +1,5 @@ /* - Copyright Red Hat, Inc. 2005 + Copyright Red Hat, Inc. 2005-2007 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 @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* @@ -21,94 +21,88 @@ */ -#ifndef utils_h -#define utils_h +#ifndef __CONGA_utils_h +#define __CONGA_utils_h #include #include "String.h" #include - class exec_cache { - public: - exec_cache(const String& command, - const String& out, - const String& err, - int status, - int exec_ret) : - command(command), - out(out), - err(err), - status(status), - exec_ret(exec_ret) {} - - const String command; - const String out; - const String err; - const int status; - const int exec_ret; - + public: + exec_cache( const String& command, + const String& out, + const String& err, + int status, + int exec_ret) : + command(command), + out(out), + err(err), + status(status), + exec_ret(exec_ret) {} + + const String command; + const String out; + const String err; + const int status; + const int exec_ret; }; class utils { - public: - static String replace(const String& what, - const String& with, - const String& in_str); - - static String hash_str(const String& txt); - - static String strip(String str) - { return rstrip(lstrip(str)); } - static String lstrip(String str); - static String rstrip(String str); - - static String strip(String str, - const String& del) - { return rstrip(lstrip(str, del), del); } - static String lstrip(String str, - const String& del); - static String rstrip(String str, - const String& del); - - static std::vector split(const String& str, - const String& del); - static std::vector split(const String& str); - - static String to_lower(const String& str); - static String to_upper(const String& str); - - - // static int to_int(const String& str); - static long long to_long(const String& str); - static float to_float(const String& str); - - - static String to_string(int value); - static String to_string(long value); - static String to_string(long long value); - static String to_string(bool value); - - - static int execute(const String& path, - const std::vector& args, - String& out, - String& err, - int& status, - bool caching=true); - static void clear_cache(); - static std::map cache; - + public: + static String replace( const String& what, + const String& with, + const String& in_str); + + static String hash_str(const String& txt); + + static String strip(String str) + { + return rstrip(lstrip(str)); + } + static String lstrip(String str); + static String rstrip(String str); + + static String strip(String str, const String& del) + { + return rstrip(lstrip(str, del), del); + } + static String lstrip(String str, const String& del); + static String rstrip(String str, const String& del); + + static std::vector split(const String& str, const String& del); + static std::vector split(const String& str); + + static String to_lower(const String& str); + static String to_upper(const String& str); + + //static int to_int(const String& str); + static long long to_long(const String& str); + static float to_float(const String& str); + + static String to_string(int value); + static String to_string(long value); + static String to_string(long long value); + static String to_string(bool value); + + static int execute( const String& path, + const std::vector& args, + String& out, + String& err, + int& status, + bool caching=true); + + static void clear_cache(); + static std::map cache; }; inline String command_not_found_error_msg(const String& command) { - return String("command \"") + command + "\" not found/not executable"; + return String("command \"") + command + "\" not found/not executable"; } - -#endif // utils_h +#endif