From 0610686ce646e21bb7bf5807508afe1d981177a5 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 18 Jul 2005 06:18:50 +0000 Subject: [PATCH] util:: source review --- include/util/ConfigFile.hpp | 4 ++-- include/util/RandGen.hpp | 12 ++++++------ include/util/Singleton.hpp | 8 ++++---- include/util/Timer.hpp | 5 ++++- include/util/VersionInfo.hpp | 4 ++-- src/util/FileBuffer.cpp | 10 ++++++++-- src/util/Timer.cpp | 22 +++++++++++++++++----- src/util/VersionInfo.cpp | 4 ++-- src/util/filesys/filesys.cpp | 5 ++++- 9 files changed, 49 insertions(+), 25 deletions(-) diff --git a/include/util/ConfigFile.hpp b/include/util/ConfigFile.hpp index 1d4e46a..3cc11d8 100644 --- a/include/util/ConfigFile.hpp +++ b/include/util/ConfigFile.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: ConfigFile.hpp,v 1.4 2005/07/05 06:44:56 cozman Exp $ +// $Id: ConfigFile.hpp,v 1.5 2005/07/18 06:18:51 cozman Exp $ #ifndef PHOTON_UTIL_CONFIGFILE_HPP #define PHOTON_UTIL_CONFIGFILE_HPP @@ -44,7 +44,7 @@ public: // types used in ConfigFile typedef std::pair Variable; typedef std::list< Variable > Section; - typedef std::pair< std::string, std::list< Variable > > NamedSection; + typedef std::pair< std::string, Section > NamedSection; typedef std::list< NamedSection > Layout; // Group: (Con/De)structors diff --git a/include/util/RandGen.hpp b/include/util/RandGen.hpp index 0b26e3f..155e270 100644 --- a/include/util/RandGen.hpp +++ b/include/util/RandGen.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: RandGen.hpp,v 1.4 2005/03/15 18:47:46 cozman Exp $ +// $Id: RandGen.hpp,v 1.5 2005/07/18 06:18:51 cozman Exp $ #ifndef PHOTON_UTIL_RANDGEN_HPP #define PHOTON_UTIL_RANDGEN_HPP @@ -98,11 +98,11 @@ private: // utilities unsigned long genrand_int32(); //base of all generation private: // constants - static const unsigned long N=624; - static const unsigned long M=397; - static const unsigned long MATRIX_A=0x9908b0dfUL; - static const unsigned long UPPER_MASK=0x80000000UL; - static const unsigned long LOWER_MASK=0x7fffffffUL; + static const unsigned long N = 624; + static const unsigned long M = 397; + static const unsigned long MATRIX_A = 0x9908b0dfUL; + static const unsigned long UPPER_MASK = 0x80000000UL; + static const unsigned long LOWER_MASK = 0x7fffffffUL; private: //state data unsigned long stateVector_[N]; diff --git a/include/util/Singleton.hpp b/include/util/Singleton.hpp index 7f433b8..ee17e84 100644 --- a/include/util/Singleton.hpp +++ b/include/util/Singleton.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Singleton.hpp,v 1.7 2005/03/15 18:51:00 cozman Exp $ +// $Id: Singleton.hpp,v 1.8 2005/07/18 06:18:51 cozman Exp $ #ifndef PHOTON_UTIL_SINGLETON_HPP #define PHOTON_UTIL_SINGLETON_HPP @@ -20,12 +20,12 @@ namespace util { // Class: Singleton -// Template class for singleton pattern. Is non-copyable to enforce -// correct behavior. +// Template class for singleton pattern. Is non-copyable to enforce correct +// behavior. // // Defining a Singleton: // (code) -// YourClass : public Singleton +// class YourClass : public Singleton // { // // class definition // }; diff --git a/include/util/Timer.hpp b/include/util/Timer.hpp index 3282a28..97e1932 100644 --- a/include/util/Timer.hpp +++ b/include/util/Timer.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Timer.hpp,v 1.1 2005/03/02 08:39:03 cozman Exp $ +// $Id: Timer.hpp,v 1.2 2005/07/18 06:18:51 cozman Exp $ #ifndef PHOTON_UTIL_TIMER_HPP #define PHOTON_UTIL_TIMER_HPP @@ -71,6 +71,9 @@ public: // True if timer is paused, false if timer is running. bool isPaused() const; +private: + double getTimeInternal() const; // get time from source timer + // data members private: AppCore& appCore_; diff --git a/include/util/VersionInfo.hpp b/include/util/VersionInfo.hpp index 8d30cc7..f173557 100644 --- a/include/util/VersionInfo.hpp +++ b/include/util/VersionInfo.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: VersionInfo.hpp,v 1.6 2005/04/21 19:30:19 cozman Exp $ +// $Id: VersionInfo.hpp,v 1.7 2005/07/18 06:18:51 cozman Exp $ #ifndef PHOTON_UTIL_VERSIONINFO_HPP #define PHOTON_UTIL_VERSIONINFO_HPP @@ -68,7 +68,7 @@ public: // pat - Patch number. // ext - Extra info string. [default: ""] VersionInfo(unsigned int maj, unsigned int min, unsigned int pat, - std::string ext=""); + const std::string& ext=""); //operators bool operator<(const VersionInfo &rhs) const; diff --git a/src/util/FileBuffer.cpp b/src/util/FileBuffer.cpp index cc15c00..dff466c 100644 --- a/src/util/FileBuffer.cpp +++ b/src/util/FileBuffer.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: FileBuffer.cpp,v 1.7 2005/06/27 04:24:16 cozman Exp $ +// $Id: FileBuffer.cpp,v 1.8 2005/07/18 06:18:50 cozman Exp $ #include "util/FileBuffer.hpp" @@ -27,7 +27,12 @@ FileBuffer::FileBuffer(const std::string& filename) } FileBuffer::~FileBuffer() -{} +{ + if(file_ != 0) + { + close(); + } +} void FileBuffer::open(const std::string& filename) { @@ -46,6 +51,7 @@ void FileBuffer::close() } PHYSFS_close(file_); + file_ = 0; } std::vector FileBuffer::getData(int amount) diff --git a/src/util/Timer.cpp b/src/util/Timer.cpp index bb4e9c3..ed2c42d 100644 --- a/src/util/Timer.cpp +++ b/src/util/Timer.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Timer.cpp,v 1.2 2005/03/15 18:52:07 cozman Exp $ +// $Id: Timer.cpp,v 1.3 2005/07/18 06:18:50 cozman Exp $ #include "util/Timer.hpp" @@ -27,7 +27,7 @@ Timer::~Timer() void Timer::reset() { - lastPause_ = pausedTime_ = appCore_.getTime(); + lastPause_ = pausedTime_ = getTimeInternal(); paused_ = false; } @@ -35,7 +35,7 @@ void Timer::pause() { if(!paused_) { - lastPause_ = appCore_.getTime(); + lastPause_ = getTimeInternal(); paused_ = true; } } @@ -45,7 +45,7 @@ void Timer::unpause() if(paused_) { //when unpausing update the total paused time by that pause - pausedTime_ += (appCore_.getTime()-lastPause_); + pausedTime_ += (getTimeInternal()-lastPause_); paused_ = false; } } @@ -60,7 +60,7 @@ double Timer::getTime() const else { //paused time is the total time the program has been paused - return appCore_.getTime() - pausedTime_; + return getTimeInternal() - pausedTime_; } } @@ -69,5 +69,17 @@ bool Timer::isPaused() const return paused_; } +double Timer::getTimeInternal() const +{ + if(appTimeLinked_) + { + return appCore_.getTime(); // get from AppCore timer if linked + } + else + { + return glfwGetTime(); // raw timer if not linked + } +} + } } diff --git a/src/util/VersionInfo.cpp b/src/util/VersionInfo.cpp index 370a50b..bb1515f 100644 --- a/src/util/VersionInfo.cpp +++ b/src/util/VersionInfo.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: VersionInfo.cpp,v 1.7 2005/04/21 19:30:19 cozman Exp $ +// $Id: VersionInfo.cpp,v 1.8 2005/07/18 06:18:50 cozman Exp $ #include "util/VersionInfo.hpp" @@ -19,7 +19,7 @@ namespace util { VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int pat, - std::string ext) : + const std::string& ext) : majorRelease(maj), minorRelease(min), patch(pat), extra(ext) {} diff --git a/src/util/filesys/filesys.cpp b/src/util/filesys/filesys.cpp index 7b1ab3a..062856b 100644 --- a/src/util/filesys/filesys.cpp +++ b/src/util/filesys/filesys.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: filesys.cpp,v 1.4 2005/02/16 06:58:26 cozman Exp $ +// $Id: filesys.cpp,v 1.5 2005/07/18 06:18:50 cozman Exp $ #include "util/filesys/filesys.hpp" @@ -17,6 +17,9 @@ namespace util namespace filesys { +// most functions are simple wrappers around PhysFS functions of virtually +// the same name, some convert 'char**'s into 'vector's. + std::vector getCDDirs() { std::vector dirs;