commit 07252d2424ed398a819ab52695f5b16af83b4baf Author: James Turk Date: Thu Jan 27 03:35:23 2005 +0000 initial import (exceptions,types, and logging,oh my!) diff --git a/devcpp/photon.dev b/devcpp/photon.dev new file mode 100644 index 0000000..b555b71 --- /dev/null +++ b/devcpp/photon.dev @@ -0,0 +1,199 @@ +[Project] +FileName=photon.dev +Name=photon +UnitCount=15 +Type=2 +Ver=1 +ObjFiles= +Includes=../include +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=1 +Icon= +ExeOutput=..\lib +ObjectOutput=..\devcpp +OverrideOutput=0 +OverrideOutputName=photon.a +HostApplication= +Folders=include,include/util,src,src/util +CommandLine= +UseCustomMakefile=0 +CustomMakefile= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 + +[Unit1] +FileName=..\include\types.h +CompileCpp=1 +Folder=include +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=..\include\Log.h +CompileCpp=1 +Folder=include +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=..\include\LogSink.h +CompileCpp=1 +Folder=include +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=..\include\util\ConfigFile.h +CompileCpp=1 +Folder=include/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=..\include\util\RandGen.h +CompileCpp=1 +Folder=include/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=..\include\util\VersionInfo.h +CompileCpp=1 +Folder=include/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=..\include\util\ZipBuffer.h +CompileCpp=1 +Folder=include/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=..\src\Log.cpp +CompileCpp=1 +Folder=src +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=..\src\LogSink.cpp +CompileCpp=1 +Folder=src +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=..\src\util\ConfigFile.cpp +CompileCpp=1 +Folder=src/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=..\src\util\RandGen.cpp +CompileCpp=1 +Folder=src/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=..\src\util\VersionInfo.cpp +CompileCpp=1 +Folder=src/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=..\src\util\ZipBuffer.cpp +CompileCpp=1 +Folder=src/util +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=0 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription= +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit14] +FileName=..\src\exceptions.cpp +CompileCpp=1 +Folder=src +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=..\include\exceptions.h +CompileCpp=1 +Folder=include +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/include/Log.h b/include/Log.h new file mode 100644 index 0000000..600a14e --- /dev/null +++ b/include/Log.h @@ -0,0 +1,131 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: Log.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: Log.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_LOG_H +#define PHOTON_LOG_H + +#include +#include +#include + +#include "LogSink.h" + +namespace photon +{ + +// Class: Log +// Log class for photon, Log passes all messages to any attached sinks, which +// can then take care of any output which is desired. +class Log +{ + +public: + Log(); + ~Log(); + +// Group: Sink Maintenance +public: + + // Function: addSink + // Adds a sink to the Log, sinks are given access to all messages passed + // into the log. + // + // Parameters: + // sink - Pointer to to add to Log. + void addSink(LogSink *sink); + + // Function: removeSink + // Remove a sink from the log by name. + // + // Parameters: + // sinkName - Name of sink to remove. + void removeSink(std::string sinkName); + + // Function: removeSink + // Remove a sink from the log. + // + // Parameters: + // sink - Pointer to sink to remove. + void removeSink(LogSink *sink); + + // Function: removeSinks + // Remove all sinks from log. + void removeSinks(); + +// Group: Stream Access +public: + + // Function: note + // Accesses stream, any messages passed into note are given to associated + // with a of LOG_NOTE. + // + // Returns: + // Stream to pass errors to. + std::ostream& note(); + + // Function: verbose + // Accesses stream, any messages passed into verbose are given to + // associated with a of LOG_VERBOSE. + // + // Returns: + // Stream to pass errors to. + std::ostream& verbose(); + + // Function: warning + // Accesses stream, any messages passed into warning are given to + // associated with a of LOG_WARNING. + // + // Returns: + // Stream to pass errors to. + std::ostream& warning(); + + // Function: error + // Accesses stream, any messages passed into error are given to associated + // with a of LOG_ERROR. + // + // Returns: + // Stream to pass errors to. + std::ostream& error(); + + // Function: critical + // Accesses stream, any messages passed into critical are given to + // associated with a of LOG_CRITICAL. + // + // Returns: + // Stream to pass errors to. + std::ostream& critical(); + + // Function: flush + // Flushes the log, is generally not required. Output is handed to the + // sinks when flush is called. + void flush(); + +private: + std::stringstream buffer_; + LogLevel lastLevel_; + std::list sinks_; + + //assignment left undefined + Log(const Log &rhs); + Log& operator=(const Log &rhs); +}; + +//Define a log to be used throughout photon +extern Log log; + +} + +#endif //PHOTON_LOG_H diff --git a/include/LogSink.h b/include/LogSink.h new file mode 100644 index 0000000..0a30c37 --- /dev/null +++ b/include/LogSink.h @@ -0,0 +1,149 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: LogSink.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: LogSink.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_LOGSINK_H +#define PHOTON_LOGSINK_H + +#include +#include + +namespace photon +{ + +// Enum: LogLevel +// Enumeration defining severity of an error. +// +// Values: +// LOG_NOTE - A note, highest priority so that they are always +// printed, not used for errors, only for temporary +// notes. +// LOG_VERBOSE - Verbose warning, lowest priority. +// LOG_WARNING - A warning, used for non critical failures. +// LOG_ERROR - Normal error, used for potential serious failures. +// LOG_CRITICAL - Critical error, used for failures which are threats to +// stability. +enum LogLevel +{ + LOG_NOTE, + LOG_VERBOSE, + LOG_WARNING, + LOG_ERROR, + LOG_CRITICAL +}; + +// Class: LogSink +// Base class for all LogSinks to be used with , derived classes must +// define message(LogLevel level, std::string string). +// A LogSink recieves any messages passed to the log it's registered with. +class LogSink +{ + +// Group: (Con/De)structors +public: + + // Function: LogSink + // LogSink constructor, requires a name. + // + // Parameters: + // name_ - Name of LogSink, every LogSink should have a unique name. + // dynamic_ - Tells if the sink is dynamically allocated. + // This flag is false by default, and should be true if Log + // should delete the sink when it is done. + LogSink(std::string name, bool dynamic=false); + + // Function: ~LogSink + // Virtual destructor, available to make inheritance safe. + virtual ~LogSink(); + +// Group: Functions +public: + + // Function: writeMessage + // Pure virtual function which derived classes must define to write the + // message. + // + // Parameters: + // level - of log event. + // msg - String describing log message. + virtual void writeMessage(LogLevel level, std::string msg)=0; + +// Group: Accessors +public: + + // Function: getName + // Gets name of the sink. + // + // Returns: + // Name of the LogSink. + std::string getName() const; + + // Function: isDynamic + // Checks if sink is dynamic. + // + // Returns: + // True if log is dynamically allocated, false if not. + bool isDynamic() const; + +private: + std::string name_; + bool dynamic_; + + //assignment left undefined + LogSink(const LogSink&); + LogSink& operator=(const LogSink&); +}; + + +// Class: ConsoleSink +// to be used with for simple console output. +class ConsoleSink : public LogSink +{ +public: + ConsoleSink(std::string name, bool dynamic=false); + virtual ~ConsoleSink(); + + virtual void writeMessage(LogLevel level, std::string msg); +}; + +// Class: TextSink +// to be used with for simple text file output. +class TextSink : public LogSink +{ +public: + TextSink(std::string name, bool dynamic=false); + virtual ~TextSink(); + + virtual void writeMessage(LogLevel level, std::string msg); +private: + std::ofstream out_; +}; + +// Class: HtmlSink +// to be used with for simple HTML output. +class HtmlSink : public LogSink +{ +public: + HtmlSink(std::string name, bool dynamic=false); + virtual ~HtmlSink(); + + virtual void writeMessage(LogLevel level, std::string msg); +private: + std::ofstream out_; +}; + +} + +#endif //PHOTON_LOGSINK_H diff --git a/include/exceptions.h b/include/exceptions.h new file mode 100644 index 0000000..286ea3d --- /dev/null +++ b/include/exceptions.h @@ -0,0 +1,225 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: exceptions.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: exceptions.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_EXCEPTIONS_H +#define PHOTON_EXCEPTIONS_H + +#include +#include + +namespace photon +{ + +// Class: Throwable +// Throwable is the base exception class for Photon. +// +// Throwable is pure virtual, and can not be used directly, Exception and +// Error are available for non-specific exceptions. +// +// Children: +// - Base class for all non-fatal exceptions. +// - Base class for all potentially fatal exceptions. +class Throwable +{ +public: + Throwable() throw(); + Throwable(std::string description) throw(); + virtual ~Throwable() throw()=0; + + std::string getDesc() const throw(); + +private: + std::string description_; +}; + +// Class: Exception +// Exception is the base exception class, all exceptions inherit from +// it, and it inherits from . +// Exception should be used for hard to classify exceptions. +// +// Exception's children should be used when a problem occurs which is +// recoverable. +// +// See Also: +// +// +// Parent: +// +// +// Children: +// +// +// +// +class Exception : public Throwable +{ +public: + Exception() throw(); + Exception(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const Exception& rhs); +}; + +// Class: ArgumentException +// ArgumentException should be thrown when an argument is passed to a function +// that is invalid. +// +// Parent: +// +class ArgumentException : public Exception +{ +public: + ArgumentException() throw(); + ArgumentException(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const ArgumentException& rhs); +}; + +// Class: PreconditionException +// PreconditionException should be thrown when a precondition is not met. +// +// Parent: +// +class PreconditionException : public Exception +{ +public: + PreconditionException() throw(); + PreconditionException(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const PreconditionException& rhs); +}; + +// Class: RangeException +// RangeException should be thrown if something (such as an array bound) is out +// of bounds. +// +// Parent: +// +class RangeException : public Exception +{ +public: + RangeException() throw(); + RangeException(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const RangeException& rhs); +}; + +// Class: ResourceException +// ResourceException should be thrown if there is a problem accessing a +// resource. +// +// Parent: +// +class ResourceException : public Exception +{ +public: + ResourceException() throw(); + ResourceException(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const ResourceException& rhs); +}; + +// Class: Error +// GeneralError is the base error class, all errors inherit from it, and it +// inherits from . +// Error should be used for hard to classify errors. +// +// Errors should be used when a problem occurs which is difficult to just +// ignore, usually more severe than exceptions. +// +// See Also: +// +// +// Parent: +// +// +// Children: +// +// +class Error : public Throwable +{ +public: + Error() throw(); + Error(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const Error& rhs); +}; + +// Class: MemoryError +// MemoryError should be thrown if there is an error allocating memory. +// +// Parent: +// +class MemoryError : public Error +{ +public: + MemoryError() throw(); + MemoryError(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const MemoryError& rhs); +}; + +// Class: APIError +// APIError should be thrown if an error occurs in code which is not part of +// Photon. +// +// Parent: +// +class APIError : public Error +{ +public: + APIError() throw(); + APIError(std::string description) throw(); + friend std::ostream& operator<<(std::ostream& os, + const APIError& rhs); +}; + + +// Function: require +// Similar to an assert, given a condition checks if it is true, and if it is +// not, throws an exception. +// +// An example of when to use require would be in a function that does an +// operation to a certain pointer: +// void func() +// { +// require(pointer != NULL,"pointer must be valid"); +// +// pointer->doSomething(); +// } +// +// Template Parameters: +// ExceptionT - type of exception to throw +// +// Parameters: +// condition - boolean expression to be satisfied +// description - description of this condition (optional parameter) +template +void require(bool condition, std::string description=""); + +//definition of require template +template +void require(bool condition, std::string description) +{ + if(!condition) + { + throw ExceptionT(description); + } +} + +} + +#endif //PHOTON_EXCEPTIONS_H diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..0670c18 --- /dev/null +++ b/include/types.h @@ -0,0 +1,40 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: types.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: types.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_TYPES_H +#define PHOTON_TYPES_H + +// Title: Basic Types + +namespace photon { + +// Group: Types + + // Typedef: ubyte + // Unsigned byte, alias for unsigned char. + typedef unsigned char ubyte; + + // Typedef: uint + // Alias for unsigned integer. + typedef unsigned int uint; + + // Typedef: scalar + // Scalar value, used throughout photon. (double or float) + typedef double scalar; + +} + +#endif //PHOTON_TYPES_H diff --git a/include/util/ConfigFile.h b/include/util/ConfigFile.h new file mode 100644 index 0000000..84a2752 --- /dev/null +++ b/include/util/ConfigFile.h @@ -0,0 +1,28 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: ConfigFile.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: ConfigFile.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_UTIL_CONFIGFILE_H +#define PHOTON_UTIL_CONFIGFILE_H + +namespace photon { +namespace util { + + + +} +} + +#endif //PHOTON_UTIL_CONFIGFILE_H diff --git a/include/util/RandGen.h b/include/util/RandGen.h new file mode 100644 index 0000000..733baca --- /dev/null +++ b/include/util/RandGen.h @@ -0,0 +1,28 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: RandGen.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: RandGen.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_UTIL_RANDGEN_H +#define PHOTON_UTIL_RANDGEN_H + +namespace photon { +namespace util { + + + +} +} + +#endif //PHOTON_UTIL_RANDGEN_H diff --git a/include/util/VersionInfo.h b/include/util/VersionInfo.h new file mode 100644 index 0000000..18d3f9e --- /dev/null +++ b/include/util/VersionInfo.h @@ -0,0 +1,28 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: VersionInfo.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: VersionInfo.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_UTIL_VERSIONINFO_H +#define PHOTON_UTIL_VERSIONINFO_H + +namespace photon { +namespace util { + + + +} +} + +#endif //PHOTON_UTIL_VERSIONINFO_H diff --git a/include/util/ZipBuffer.h b/include/util/ZipBuffer.h new file mode 100644 index 0000000..8e73390 --- /dev/null +++ b/include/util/ZipBuffer.h @@ -0,0 +1,28 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: ZipBuffer.h,v 1.1 2005/01/27 03:35:23 cozman Exp $ +// +// Revisions: +// $Log: ZipBuffer.h,v $ +// Revision 1.1 2005/01/27 03:35:23 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#ifndef PHOTON_UTIL_ZIPBUFFER_H +#define PHOTON_UTIL_ZIPBUFFER_H + +namespace photon { +namespace util { + + + +} +} + +#endif //PHOTON_UTIL_ZIPBUFFER_H diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..0ebb3ce --- /dev/null +++ b/license.txt @@ -0,0 +1,29 @@ +Copyright (c) 2004-2005, James Turk +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of Photon nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + diff --git a/src/Log.cpp b/src/Log.cpp new file mode 100644 index 0000000..0e0d74c --- /dev/null +++ b/src/Log.cpp @@ -0,0 +1,149 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: Log.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: Log.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "Log.h" + +#include +#include "exceptions.h" + +namespace photon +{ + +Log::Log() +{ +} + +Log::~Log() +{ + flush(); + removeSinks(); +} + +void Log::addSink(LogSink *sink) +{ + for(std::list::iterator it = sinks_.begin(); + it != sinks_.end(); + ++it) + { + if(sink == *it || sink->getName() == (*it)->getName()) + { + throw Exception("Log already contains sink: " + + sink->getName()); + } + } + + sinks_.push_back(sink); +} + +void Log::removeSink(std::string sinkName) +{ + for(std::list::iterator it = sinks_.begin(); + it != sinks_.end(); + ++it) + { + if((*it)->getName() == sinkName) + { + if((*it)->isDynamic()) + { + delete *it; + } + sinks_.erase(it); + } + } +} + +void Log::removeSink(LogSink *sink) +{ + std::list::iterator it = + std::find(sinks_.begin(),sinks_.end(),sink); + + if(it != sinks_.end()) + { + if((*it)->isDynamic()) + { + delete *it; + } + sinks_.erase(it); + } +} + +void Log::removeSinks() +{ + for(std::list::iterator it = sinks_.begin(); + it != sinks_.end(); + ++it) + { + if((*it)->isDynamic()) + { + delete *it; + } + } + sinks_.clear(); +} + +void Log::flush() +{ + std::string str = buffer_.str(); + if(str.length()) + { + for(std::list::iterator it = sinks_.begin(); + it != sinks_.end(); + ++it) + { + (*it)->writeMessage(lastLevel_,str); + } + buffer_.str(""); + } +} + +std::ostream& Log::note() +{ + flush(); + lastLevel_ = LOG_NOTE; + return buffer_; +} + +std::ostream& Log::verbose() +{ + flush(); + lastLevel_ = LOG_VERBOSE; + return buffer_; +} + +std::ostream& Log::warning() +{ + flush(); + lastLevel_ = LOG_WARNING; + return buffer_; +} + +std::ostream& Log::error() +{ + flush(); + lastLevel_ = LOG_ERROR; + return buffer_; +} + +std::ostream& Log::critical() +{ + flush(); + lastLevel_ = LOG_CRITICAL; + return buffer_; +} + +Log log; + +} diff --git a/src/LogSink.cpp b/src/LogSink.cpp new file mode 100644 index 0000000..5bd4720 --- /dev/null +++ b/src/LogSink.cpp @@ -0,0 +1,130 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: LogSink.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: LogSink.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "LogSink.h" + +#include + +namespace photon +{ + +//LogSink + +LogSink::LogSink(std::string name, bool dynamic) : + name_(name),dynamic_(dynamic) +{ +} + +LogSink::~LogSink() +{ +} + +std::string LogSink::getName() const +{ + return name_; +} + +bool LogSink::isDynamic() const +{ + return dynamic_; +} + +//ConsoleSink + +ConsoleSink::ConsoleSink(std::string name, bool dynamic) : + LogSink(name,dynamic) +{ +} + +ConsoleSink::~ConsoleSink() +{ +} + +void ConsoleSink::writeMessage(LogLevel level, std::string msg) +{ + static char* pre[] = { " NOTE: ", + " VERBOSE: ", + " WARNING: ", + " ERROR: ", + "CRITICAL: " }; + + std::cerr << pre[static_cast(level)] << msg << std::endl; +} + +//TextSink + +TextSink::TextSink(std::string name, bool dynamic) : + LogSink(name,dynamic), + out_(std::string(name+".txt").c_str()) +{ +} + +TextSink::~TextSink() +{ + out_.close(); +} + +void TextSink::writeMessage(LogLevel level, std::string msg) +{ + static char* pre[] = { " NOTE: ", + " VERBOSE: ", + " WARNING: ", + " ERROR: ", + "CRITICAL: " }; + + out_ << pre[static_cast(level)] << msg << std::endl; +} + +//HtmlSink + +HtmlSink::HtmlSink(std::string name, bool dynamic) : + LogSink(name,dynamic), + out_(std::string(name+".html").c_str()) +{ + out_ << "Error Log\n" << std::endl << "" + << std::endl << "" << std::endl; +} + +HtmlSink::~HtmlSink() +{ + out_ << "" << std::endl; + out_.close(); +} + +void HtmlSink::writeMessage(LogLevel level, std::string msg) +{ + static char* css[] = {"note","verbose","warning","error","critical"}; + static char* pre[] = { " NOTE: ", + " VERBOSE: ", + " WARNING: ", + " ERROR: ", + "CRITICAL: " }; + + out_ << "

(level)] << "\">" + << pre[static_cast(level)] << msg << "

" << std::endl; +} + +} diff --git a/src/exceptions.cpp b/src/exceptions.cpp new file mode 100644 index 0000000..1f9f781 --- /dev/null +++ b/src/exceptions.cpp @@ -0,0 +1,101 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: exceptions.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: exceptions.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + + +#include "exceptions.h" + + +namespace photon +{ + +Throwable::Throwable() throw() {} +Throwable::Throwable(std::string description) throw() : + description_(description) {} +Throwable::~Throwable() throw() {} +std::string Throwable::getDesc() const throw() +{ + return description_; +} + +//exceptions// + +Exception::Exception() throw() {} +Exception::Exception(std::string description) throw() : + Throwable(description) {} +std::ostream& operator<<(std::ostream& os, const Exception& rhs) +{ + return os << "General exception occured. " << rhs.getDesc(); +} + +ArgumentException::ArgumentException() throw() {} +ArgumentException::ArgumentException(std::string description) throw() : + Exception(description) {} +std::ostream& operator<<(std::ostream& os, const ArgumentException& rhs) +{ + return os << "Invalid argument exception occured. " << rhs.getDesc(); +} + +PreconditionException::PreconditionException() throw() {} +PreconditionException::PreconditionException(std::string description) throw() : + Exception(description) {} +std::ostream& operator<<(std::ostream& os, const PreconditionException& rhs) +{ + return os << "Precondition exception occured. " << rhs.getDesc(); +} + +RangeException::RangeException() throw() {} +RangeException::RangeException(std::string description) throw() : + Exception(description) {} +std::ostream& operator<<(std::ostream& os, const RangeException& rhs) +{ + return os << "Out-of-range exception. " << rhs.getDesc(); +} + +ResourceException::ResourceException() throw() {} +ResourceException::ResourceException(std::string description) throw() : + Exception(description) {} +std::ostream& operator<<(std::ostream& os, const ResourceException& rhs) +{ + return os << "Resource exception. " << rhs.getDesc(); +} + +//errors// + +Error::Error() throw() {} +Error::Error(std::string description) throw() : + Throwable(description) {} +std::ostream& operator<<(std::ostream& os, const Error& rhs) +{ + return os << "General error occured. " << rhs.getDesc(); +} + +MemoryError::MemoryError() throw() {} +MemoryError::MemoryError(std::string description) throw() : + Error(description) {} +std::ostream& operator<<(std::ostream& os, const MemoryError& rhs) +{ + return os << "Memory error occured. " << rhs.getDesc(); +} + +APIError::APIError() throw() {} +APIError::APIError(std::string description) throw() : + Error(description) {} +std::ostream& operator<<(std::ostream& os, const APIError& rhs) +{ + return os << "Error occured within another library. " << rhs.getDesc(); +} + +} diff --git a/src/util/ConfigFile.cpp b/src/util/ConfigFile.cpp new file mode 100644 index 0000000..c35536a --- /dev/null +++ b/src/util/ConfigFile.cpp @@ -0,0 +1,26 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: ConfigFile.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: ConfigFile.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "util/ConfigFile.h" + + +namespace photon { +namespace util { + + + +} +} diff --git a/src/util/RandGen.cpp b/src/util/RandGen.cpp new file mode 100644 index 0000000..2ba2599 --- /dev/null +++ b/src/util/RandGen.cpp @@ -0,0 +1,26 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: RandGen.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: RandGen.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "util/RandGen.h" + + +namespace photon { +namespace util { + + + +} +} diff --git a/src/util/VersionInfo.cpp b/src/util/VersionInfo.cpp new file mode 100644 index 0000000..a8f8ec4 --- /dev/null +++ b/src/util/VersionInfo.cpp @@ -0,0 +1,26 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: VersionInfo.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: VersionInfo.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "util/VersionInfo.h" + + +namespace photon { +namespace util { + + + +} +} diff --git a/src/util/ZipBuffer.cpp b/src/util/ZipBuffer.cpp new file mode 100644 index 0000000..5cbf784 --- /dev/null +++ b/src/util/ZipBuffer.cpp @@ -0,0 +1,26 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: ZipBuffer.cpp,v 1.1 2005/01/27 03:35:24 cozman Exp $ +// +// Revisions: +// $Log: ZipBuffer.cpp,v $ +// Revision 1.1 2005/01/27 03:35:24 cozman +// initial import (exceptions,types, and logging,oh my!) +// +// + +#include "util/ZipBuffer.h" + + +namespace photon { +namespace util { + + + +} +}