From 9a8b4dab10f03d8207481c59d4c404824c15f36d Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 7 Jan 1999 20:25:32 +0000 Subject: [PATCH] Portability changes and updates from Bernie Bright. --- Time/event.cxx | 97 +++++++++++++++++++++++++++++++++------------- Time/event.hxx | 55 +++++++++++++------------- Time/fg_time.cxx | 46 ++++++++++++++-------- Time/fg_time.hxx | 11 +++++- Time/light.cxx | 33 ++++++++++------ Time/sunpos.cxx | 17 ++++++-- Time/sunpos.hxx | 8 +++- Time/timestamp.hxx | 10 ++++- 8 files changed, 186 insertions(+), 91 deletions(-) diff --git a/Time/event.cxx b/Time/event.cxx index 479438181..1126e03dc 100644 --- a/Time/event.cxx +++ b/Time/event.cxx @@ -26,11 +26,23 @@ # include #endif -#include -#include +#include -#ifdef HAVE_STDLIB_H -#include +#include "Include/compiler.h" + +#include STL_ALGORITHM +#include STL_FUNCTIONAL + +#ifdef FG_HAVE_STD_INCLUDES +# include +# ifdef HAVE_STDLIB_H +# include +# endif +#else +# include +# ifdef HAVE_STDLIB_H +# include +# endif #endif #if defined( HAVE_WINDOWS_H ) && defined(__MWERKS__) @@ -39,30 +51,24 @@ // contains milliseconds #endif -#if defined( linux ) || defined( __FreeBSD__ ) -# define _G_NO_EXTERN_TEMPLATES -#endif - -#include "Include/fg_stl_config.h" -#include STL_ALGORITHM -#include STL_FUNCTIONAL - #include #include "event.hxx" +FG_USING_STD(for_each); +FG_USING_STD(mem_fun); fgEVENT_MGR global_events; fgEVENT::fgEVENT( const string& desc, const fgCallback& cb, - EventState _status, - int _interval ) + EventState evt_status, + int evt_interval ) : description(desc), event_cb(cb.clone()), - status(_status), - interval(_interval), + status(evt_status), + interval(evt_interval), cum_time(0), min_time(100000), max_time(0), @@ -70,14 +76,10 @@ fgEVENT::fgEVENT( const string& desc, { } +#if 0 fgEVENT::fgEVENT( const fgEVENT& evt ) : description(evt.description), -#ifdef _FG_NEED_AUTO_PTR - // Ugly - cast away const until proper auto_ptr implementation. - event_cb((auto_ptr&)(evt.event_cb)), -#else event_cb(evt.event_cb), -#endif status(evt.status), interval(evt.interval), last_run(evt.last_run), @@ -90,9 +92,30 @@ fgEVENT::fgEVENT( const fgEVENT& evt ) { } +fgEVENT& +fgEVENT::operator= ( const fgEVENT& evt ) +{ + if ( this != &evt ) + { + description = evt.description; + event_cb = evt.event_cb; + status = evt.status; + interval = evt.interval; + last_run = evt.last_run; + current = evt.current; + next_run = evt.next_run; + cum_time = evt.cum_time; + min_time = evt.min_time; + max_time = evt.max_time; + count = evt.count; + } + return *this; +} +#endif + fgEVENT::~fgEVENT() { -// cout << "fgEVENT::~fgEVENT" << endl; + delete event_cb; } void @@ -167,12 +190,12 @@ fgEVENT_MGR::Register( const string& desc, fgEVENT::EventState status, int interval ) { - fgEVENT e( desc, cb, status, interval ); + fgEVENT* e = new fgEVENT( desc, cb, status, interval ); FG_LOG( FG_EVENT, FG_INFO, "Registering event: " << desc ); // Actually run the event - e.run(); + e->run(); // Now add to event_table event_table.push_back(e); @@ -206,10 +229,18 @@ fgEVENT_MGR::PrintStats() FG_LOG( FG_EVENT, FG_INFO, "Event Stats" ); FG_LOG( FG_EVENT, FG_INFO, "-----------" ); + ConstEventIterator first = event_table.begin(); + ConstEventIterator last = event_table.end(); + while ( first != last ) + { + (*first)->PrintStats(); + ++first; + } +#if 0 // msvc++ 6.0 barfs at mem_fun() for_each( event_table.begin(), event_table.end(), - mem_fun_ref( &fgEVENT::PrintStats )); - + mem_fun( &fgEVENT::PrintStats ) ); +#endif FG_LOG( FG_EVENT, FG_INFO, ""); } @@ -236,7 +267,7 @@ void fgEVENT_MGR::Process( void ) { // while ( current != last ) { for ( i = 0; i < size; i++ ) { // e = *current++; - e_ptr = &event_table[i]; + e_ptr = event_table[i]; if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) { FG_LOG( FG_EVENT, FG_DEBUG, " Item " << i << " current " << cur_time.get_seconds() @@ -261,10 +292,22 @@ void fgEVENT_MGR::Process( void ) { // Destructor fgEVENT_MGR::~fgEVENT_MGR( void ) { + EventIterator first = event_table.begin(); + EventIterator last = event_table.end(); + for ( ; first != last; ++first ) + { + delete (*first); + } + + run_queue.erase( run_queue.begin(), run_queue.end() ); + event_table.erase( event_table.begin(), event_table.end() ); } // $Log$ +// Revision 1.14 1999/01/07 20:25:32 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.13 1998/12/04 01:32:46 curt // Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some // convenience inline operators. diff --git a/Time/event.hxx b/Time/event.hxx index c795b79a7..57d81e81d 100644 --- a/Time/event.hxx +++ b/Time/event.hxx @@ -31,29 +31,16 @@ #endif -#if defined ( __sun__ ) || defined ( __sgi ) -extern "C" void *memmove(void *, const void *, size_t); -extern "C" void *memset(void *, int, size_t); -#endif - +#include "Include/compiler.h" +#include "Include/fg_callback.hxx" #include // STL double ended queue #include // STL list #include -#include "Include/fg_stl_config.h" - -#ifdef FG_NEED_AUTO_PTR -# include "Include/auto_ptr.hxx" -#else -# include -#endif - -#include "Include/fg_callback.hxx" - -#ifdef NEEDNAMESPACESTD -using namespace std; -#endif +FG_USING_STD(deque); +FG_USING_STD(list); +FG_USING_STD(string); #include "fg_time.hxx" #include "timestamp.hxx" @@ -69,14 +56,14 @@ public: FG_EVENT_QUEUED = 2 }; + friend class fgEVENT_MGR; + fgEVENT() {} // Required by deque<>. fgEVENT( const string& desc, const fgCallback& cb, - EventState _status, - int _interval ); - - fgEVENT( const fgEVENT& evt ); + EventState evt_status, + int evt_interval ); ~fgEVENT(); @@ -85,14 +72,17 @@ public: // void PrintStats() const; int PrintStats() const; -public: +private: + // not defined + fgEVENT( const fgEVENT& evt ); + fgEVENT& operator= ( const fgEVENT& evt ); + +private: string description; // The callback object. - // We wrap it in an auto_ptr<> because deque<> calls our copy ctor - // and dtor when inserting and removing. - auto_ptr event_cb; + fgCallback* event_cb; EventState status; // status flag @@ -112,10 +102,16 @@ public: class fgEVENT_MGR { // Event table - deque < fgEVENT > event_table; + typedef deque < fgEVENT* > EventContainer; + typedef EventContainer::iterator EventIterator; + typedef EventContainer::const_iterator ConstEventIterator; + + EventContainer event_table; // Run Queue - list < fgEVENT * > run_queue; + typedef list < fgEVENT * > RunContainer; + + RunContainer run_queue; public: @@ -170,6 +166,9 @@ extern fgEVENT_MGR global_events; // $Log$ +// Revision 1.15 1999/01/07 20:25:33 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.14 1998/12/05 14:21:28 curt // Moved struct fg_timestamp to class fgTIMESTAMP and moved it's definition // to it's own file, timestamp.hxx. diff --git a/Time/fg_time.cxx b/Time/fg_time.cxx index 4dbf4edd1..24d130f13 100644 --- a/Time/fg_time.cxx +++ b/Time/fg_time.cxx @@ -27,10 +27,18 @@ # include #endif -#include -#include -#include -#include +#include "Include/compiler.h" +#ifdef FG_HAVE_STD_INCLUDES +# include +# include +# include +# include +#else +# include +# include +# include +# include +#endif #ifdef HAVE_SYS_TIMEB_H # include // for ftime() and struct timeb @@ -264,12 +272,9 @@ time_t get_start_gmt(int year) { long int offset = -(timezone / 3600 - daylight); - FG_LOG( FG_EVENT, FG_DEBUG, - " Raw time zone offset = " << timezone ); - FG_LOG( FG_EVENT, FG_DEBUG, - " Daylight Savings = " << daylight ); - FG_LOG( FG_EVENT, FG_DEBUG, - " Local hours from GMT = " << offset); + FG_LOG( FG_EVENT, FG_DEBUG, " Raw time zone offset = " << timezone ); + FG_LOG( FG_EVENT, FG_DEBUG, " Daylight Savings = " << daylight ); + FG_LOG( FG_EVENT, FG_DEBUG, " Local hours from GMT = " << offset ); long int start_gmt = start - timezone + (daylight * 3600); @@ -280,24 +285,28 @@ time_t get_start_gmt(int year) { # endif // ! defined ( MK_TIME_IS_GMT ) } +static char* +format_time( const struct tm* p, char* buf ) +{ + sprintf( buf, "%d/%d/%2d %d:%02d:%02d", + p->tm_mon, p->tm_mday, p->tm_year, + p->tm_hour, p->tm_min, p->tm_sec); + return buf; +} // return a courser but cheaper estimate of sidereal time double sidereal_course(fgTIME *t, double lng) { struct tm *gmt; time_t start_gmt, now; double diff, part, days, hours, lst; + char tbuf[64]; gmt = t->gmt; now = t->cur_time; start_gmt = get_start_gmt(gmt->tm_year); - FG_LOG( FG_EVENT, FG_DEBUG, - " COURSE: GMT = " - << gmt->tm_mon << "/" << gmt->tm_mday << "/" << gmt->tm_year - << " " - << gmt->tm_hour << ":" << gmt->tm_min << ":" << gmt->tm_sec ); - - FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt); + FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) ); + FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt ); diff = (now - start_gmt) / (3600.0 * 24.0); @@ -389,6 +398,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t) { // $Log$ +// Revision 1.28 1999/01/07 20:25:34 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.27 1998/12/11 20:26:55 curt // #include tweaks. // diff --git a/Time/fg_time.hxx b/Time/fg_time.hxx index a308cdf1a..979c2251b 100644 --- a/Time/fg_time.hxx +++ b/Time/fg_time.hxx @@ -41,7 +41,13 @@ #endif #include -#include + +#include "Include/compiler.h" +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif #include @@ -99,6 +105,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t); // $Log$ +// Revision 1.12 1999/01/07 20:25:35 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.11 1998/12/05 15:54:29 curt // Renamed class fgFLIGHT to class FGState as per request by JSB. // diff --git a/Time/light.cxx b/Time/light.cxx index 35f9b5708..940a5960d 100644 --- a/Time/light.cxx +++ b/Time/light.cxx @@ -33,12 +33,20 @@ #include #include -#ifdef __BORLANDC__ +#include "Include/compiler.h" + +#ifdef FG_MATH_EXCEPTION_CLASH # define exception c_exception #endif -#include -#include +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif + +#include +FG_USING_STD(string); #include #include @@ -65,25 +73,23 @@ fgLIGHT::fgLIGHT( void ) { // initialize lighting tables void fgLIGHT::Init( void ) { - string path, ambient, diffuse, sky; - FG_LOG( FG_EVENT, FG_INFO, "Initializing Lighting interpolation tables." ); // build the path name to the ambient lookup table - path = current_options.get_fg_root(); - ambient = path + "/Lighting/ambient"; - diffuse = path + "/Lighting/diffuse"; - sky = path + "/Lighting/sky"; + string path = current_options.get_fg_root(); + string ambient = path + "/Lighting/ambient"; + string diffuse = path + "/Lighting/diffuse"; + string sky = path + "/Lighting/sky"; // initialize ambient table - ambient_tbl = new fgINTERPTABLE((char *)ambient.c_str()); + ambient_tbl = new fgINTERPTABLE( ambient ); // initialize diffuse table - diffuse_tbl = new fgINTERPTABLE((char *)diffuse.c_str()); + diffuse_tbl = new fgINTERPTABLE( diffuse ); // initialize sky table - sky_tbl = new fgINTERPTABLE((char *)sky.c_str()); + sky_tbl = new fgINTERPTABLE( sky ); } @@ -214,6 +220,9 @@ fgLIGHT::~fgLIGHT( void ) { // $Log$ +// Revision 1.25 1999/01/07 20:25:36 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.24 1998/12/09 18:50:35 curt // Converted "class fgVIEW" to "class FGView" and updated to make data // members private and make required accessor functions. diff --git a/Time/sunpos.cxx b/Time/sunpos.cxx index cbe84f920..0a29b35a3 100644 --- a/Time/sunpos.cxx +++ b/Time/sunpos.cxx @@ -39,9 +39,17 @@ # include #endif -#include -#include -#include +#include "Include/compiler.h" +#ifdef FG_HAVE_STD_INCLUDES +# include +# include +# include +#else +# include +# include +# include +#endif + //#include #include @@ -427,6 +435,9 @@ void fgUpdateSunPos( void ) { // $Log$ +// Revision 1.19 1999/01/07 20:25:37 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.18 1998/12/09 18:50:36 curt // Converted "class fgVIEW" to "class FGView" and updated to make data // members private and make required accessor functions. diff --git a/Time/sunpos.hxx b/Time/sunpos.hxx index 878dde130..5ae3d0d7b 100644 --- a/Time/sunpos.hxx +++ b/Time/sunpos.hxx @@ -44,8 +44,12 @@ # error This library requires C++ #endif - -#include +#include "Include/compiler.h" +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif /* update the cur_time_params structure with the current sun position */ void fgUpdateSunPos( void ); diff --git a/Time/timestamp.hxx b/Time/timestamp.hxx index c27eaefd5..42f8734d4 100644 --- a/Time/timestamp.hxx +++ b/Time/timestamp.hxx @@ -40,7 +40,12 @@ # include #endif -#include +#include "Include/compiler.h" +#ifdef FG_HAVE_STD_INCLUDES +# include +#else +# include +#endif #ifdef HAVE_SYS_TIMEB_H # include // for ftime() and struct timeb @@ -158,6 +163,9 @@ inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b) // $Log$ +// Revision 1.3 1999/01/07 20:25:39 curt +// Portability changes and updates from Bernie Bright. +// // Revision 1.2 1998/12/11 20:26:56 curt // #include tweaks. //