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_STATIC_LOGGER 00028 #define ESLA_STATIC_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 00046 class StaticLogger { 00047 friend class Writer ; 00048 00049 public: 00050 static StaticLogger& instance() ; 00051 00052 struct Beginl { 00053 Beginl(); 00054 } ; 00055 struct Endl { 00056 Endl() ; 00057 } ; 00058 static const Endl endl ; 00059 static const Beginl beginl ; 00060 00061 00062 00063 static bool connect(Writer* w, const std::string& name, bool active = true) ; 00064 static bool disconnect(const std::string& name) ; 00065 static void disconnect_all() ; 00066 00067 static void activate(const std::string& name) ; 00068 static void deactivate(const std::string& name) ; 00069 static void activate_alone(const std::string& name) ; 00070 static void activate_all() ; 00071 static void deactivate_all() ; 00072 static bool is_activated(const std::string& name) ; 00073 00074 private: 00075 StaticLogger() ; 00076 ~StaticLogger() ; 00077 static StaticLogger* instance_ ; 00078 00079 struct WInfo { 00080 WInfo() ; 00081 WInfo(Writer*, const std::string&, bool) ; 00082 WInfo(const WInfo&) ; 00083 WInfo operator=(const WInfo&) ; 00084 00085 SmartPointer<Writer> writer_ ; 00086 bool active_ ; 00087 std::string name_ ; 00088 } ; 00089 00090 typedef std::map<std::string, WInfo> Map ; 00091 static Map map_ ; 00092 00093 static void write(const std::string& s) ; 00094 static void write_endl() ; 00095 static void write_beginl() ; 00096 00097 friend StaticLogger& operator << (StaticLogger&, const StaticLogger::Beginl&) ; 00098 friend StaticLogger& operator << (StaticLogger&, const StaticLogger::Endl&) ; 00099 friend StaticLogger& operator << (StaticLogger&, const std::string&) ; 00100 friend StaticLogger& operator << (StaticLogger&, const char*) ; 00101 friend StaticLogger& operator << (StaticLogger&, bool) ; 00102 friend StaticLogger& operator << (StaticLogger&, short) ; 00103 friend StaticLogger& operator << (StaticLogger&, char) ; 00104 friend StaticLogger& operator << (StaticLogger&, int) ; 00105 friend StaticLogger& operator << (StaticLogger&, unsigned int) ; 00106 friend StaticLogger& operator << (StaticLogger&, long int) ; 00107 friend StaticLogger& operator << (StaticLogger&, float) ; 00108 friend StaticLogger& operator << (StaticLogger&, double) ; 00109 } ; 00110 00111 StaticLogger& operator << (StaticLogger&, const StaticLogger::Beginl&) ; 00112 StaticLogger& operator << (StaticLogger&, const StaticLogger::Endl&) ; 00113 StaticLogger& operator << (StaticLogger&, const std::string&) ; 00114 StaticLogger& operator << (StaticLogger&, const char*) ; 00115 StaticLogger& operator << (StaticLogger&, bool) ; 00116 StaticLogger& operator << (StaticLogger&, char) ; 00117 StaticLogger& operator << (StaticLogger&, int) ; 00118 StaticLogger& operator << (StaticLogger&, unsigned int) ; 00119 StaticLogger& operator << (StaticLogger&, long int) ; 00120 StaticLogger& operator << (StaticLogger&, float) ; 00121 StaticLogger& operator << (StaticLogger&, double) ; 00122 00123 00124 00125 END_LIB_NAMESPACE 00126 00127 #endif 00128