ESLA
Embeddable Scriting LAnguage
Stanford University, Rock Fracture Project research group
© 2003
00001 /************************************************************************* 00002 * ESLA: Embeddable Scripting LAnguage 00003 * Copyright (C) 2003 Frantz Maerten 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License as 00007 * published by the Free Software Foundation; either version 2 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * If you modify this software, you should contact the author, include 00011 * a notice giving the name of the person performing the modification, 00012 * the date of modification, and the reason for such modification. 00013 * 00014 * Note that the GNU General Public License does not permit 00015 * incorporating the Software into proprietary programs. 00016 * 00017 * Contact: Frantz Maerten 00018 * frantz@pangea.stanford.edu 00019 * 00020 * Dept. of Geological & Environmental Sciences 00021 * Stanford University 00022 * Stanford, CA 94305-2115 00023 * USA 00024 *************************************************************************/ 00025 00026 00027 #ifndef ESLA_LOGGER 00028 #define ESLA_LOGGER 00029 00030 #include "../esla_namespace.h" 00031 #include "smart_pointer.h" 00032 #include <iostream> 00033 #include <fstream> 00034 #include <string> 00035 #include <set> 00036 #include <map> 00037 00038 00039 BEGIN_LIB_NAMESPACE 00040 00041 class Writer ; 00042 00057 class Logger { 00058 friend class Writer ; 00059 00060 public: 00061 struct Beginl { 00062 Beginl(); 00063 } ; 00064 struct Endl { 00065 Endl() ; 00066 } ; 00067 static const Endl endl ; 00068 static const Beginl beginl ; 00069 00070 Logger() ; 00071 virtual ~Logger() ; 00072 00073 bool connect(Writer* w, const std::string& name, bool active = true) ; 00074 void connect(const Logger&) ; 00075 bool disconnect(const std::string& name) ; 00076 void disconnect_all() ; 00077 00078 void activate(const std::string& name) ; 00079 void deactivate(const std::string& name) ; 00080 void activate_alone(const std::string& name) ; 00081 void activate_all() ; 00082 void deactivate_all() ; 00083 bool is_activated(const std::string& name) const ; 00084 00085 private: 00086 struct WInfo { 00087 WInfo() ; 00088 WInfo(Writer*, const std::string&, bool) ; 00089 WInfo(const WInfo&) ; 00090 WInfo operator=(const WInfo&) ; 00091 00092 SmartPointer<Writer> writer_ ; 00093 bool active_ ; 00094 std::string name_ ; 00095 } ; 00096 00097 typedef std::map<std::string, WInfo> Map ; 00098 Map map_ ; 00099 00100 void write(const std::string& s) ; 00101 void write_endl() ; 00102 void write_beginl() ; 00103 00104 friend Logger& operator << (Logger&, const Logger::Beginl&) ; 00105 friend Logger& operator << (Logger&, const Logger::Endl&) ; 00106 friend Logger& operator << (Logger&, const std::string&) ; 00107 friend Logger& operator << (Logger&, const char*) ; 00108 friend Logger& operator << (Logger&, bool) ; 00109 friend Logger& operator << (Logger&, short) ; 00110 friend Logger& operator << (Logger&, char) ; 00111 friend Logger& operator << (Logger&, int) ; 00112 friend Logger& operator << (Logger&, unsigned int) ; 00113 friend Logger& operator << (Logger&, long int) ; 00114 friend Logger& operator << (Logger&, float) ; 00115 friend Logger& operator << (Logger&, double) ; 00116 } ; 00117 00118 Logger& operator << (Logger&, const Logger::Beginl&) ; 00119 Logger& operator << (Logger&, const Logger::Endl&) ; 00120 Logger& operator << (Logger&, const std::string&) ; 00121 Logger& operator << (Logger&, const char*) ; 00122 Logger& operator << (Logger&, bool) ; 00123 Logger& operator << (Logger&, char) ; 00124 Logger& operator << (Logger&, int) ; 00125 Logger& operator << (Logger&, unsigned int) ; 00126 Logger& operator << (Logger&, long int) ; 00127 Logger& operator << (Logger&, float) ; 00128 Logger& operator << (Logger&, double) ; 00129 00130 00131 00132 END_LIB_NAMESPACE 00133 00134 #endif 00135