initial import (exceptions,types, and logging,oh my!)

This commit is contained in:
James Turk 2005-01-27 03:35:23 +00:00
commit 07252d2424
17 changed files with 1369 additions and 0 deletions

199
devcpp/photon.dev Normal file
View File

@ -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=

131
include/Log.h Normal file
View File

@ -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 <string>
#include <list>
#include <sstream>
#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 <LogSink> 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
// <LogSinks> with a <LogLevel> 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 <LogSinks> with a <LogLevel> 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 <LogSinks> with a <LogLevel> 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
// <LogSinks> with a <LogLevel> 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 <LogSinks> with a <LogLevel> 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<LogSink*> 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

149
include/LogSink.h Normal file
View File

@ -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 <string>
#include <fstream>
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 <Log>, 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 - <LogLevel> 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
// <LogSink> to be used with <Log> 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
// <LogSink> to be used with <Log> 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
// <LogSink> to be used with <Log> 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

225
include/exceptions.h Normal file
View File

@ -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 <string>
#include <ostream>
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:
// <Exception> - Base class for all non-fatal exceptions.
// <Error> - 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 <Throwable>.
// Exception should be used for hard to classify exceptions.
//
// Exception's children should be used when a problem occurs which is
// recoverable.
//
// See Also:
// <Error>
//
// Parent:
// <Throwable>
//
// Children:
// <ArgumentException>
// <PreconditionException>
// <RangeException>
// <ResourceException>
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:
// <Exception>
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:
// <Exception>
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:
// <Exception>
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:
// <Exception>
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 <Throwable>.
// 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:
// <Exception>
//
// Parent:
// <Throwable>
//
// Children:
// <MemoryError>
// <APIError>
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:
// <Error>
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:
// <Error>
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<PreconditionException>(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<class ExceptionT>
void require(bool condition, std::string description="");
//definition of require template
template<class ExceptionT>
void require(bool condition, std::string description)
{
if(!condition)
{
throw ExceptionT(description);
}
}
}
#endif //PHOTON_EXCEPTIONS_H

40
include/types.h Normal file
View File

@ -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

28
include/util/ConfigFile.h Normal file
View File

@ -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

28
include/util/RandGen.h Normal file
View File

@ -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

View File

@ -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

28
include/util/ZipBuffer.h Normal file
View File

@ -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

29
license.txt Normal file
View File

@ -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.

149
src/Log.cpp Normal file
View File

@ -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 <algorithm>
#include "exceptions.h"
namespace photon
{
Log::Log()
{
}
Log::~Log()
{
flush();
removeSinks();
}
void Log::addSink(LogSink *sink)
{
for(std::list<LogSink*>::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<LogSink*>::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<LogSink*>::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<LogSink*>::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<LogSink*>::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;
}

130
src/LogSink.cpp Normal file
View File

@ -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 <iostream>
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<int>(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<int>(level)] << msg << std::endl;
}
//HtmlSink
HtmlSink::HtmlSink(std::string name, bool dynamic) :
LogSink(name,dynamic),
out_(std::string(name+".html").c_str())
{
out_ << "<html><head><title>Error Log</title>\n<style type=\"text/css\">"
<< std::endl << "<!--" << std::endl
<< "p { margin: 0 }" << std::endl
<< ".note { font-style:italic color:gray }" << std::endl
<< ".verbose { font-style:italic; background:yellow; font-size:small }"
<< std::endl
<< ".warning { font-weight:bold; background:yellow }" << std::endl
<< ".error { font-weight:bold; background:orange }" << std::endl
<< ".critical { font-weight:bold; background:red; color:white }"
<< std::endl
<< "-->" << std::endl << "</style>" << std::endl << "</head>"
<< std::endl << "<body>" << std::endl;
}
HtmlSink::~HtmlSink()
{
out_ << "</body></html>" << 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_ << "<p class=\"" << css[static_cast<int>(level)] << "\">"
<< pre[static_cast<int>(level)] << msg << "</p>" << std::endl;
}
}

101
src/exceptions.cpp Normal file
View File

@ -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();
}
}

26
src/util/ConfigFile.cpp Normal file
View File

@ -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 {
}
}

26
src/util/RandGen.cpp Normal file
View File

@ -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 {
}
}

26
src/util/VersionInfo.cpp Normal file
View File

@ -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 {
}
}

26
src/util/ZipBuffer.cpp Normal file
View File

@ -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 {
}
}