]> git.mxchange.org Git - flightgear.git/commitdiff
Portability changes and updates from Bernie Bright.
authorcurt <curt>
Thu, 7 Jan 1999 20:25:32 +0000 (20:25 +0000)
committercurt <curt>
Thu, 7 Jan 1999 20:25:32 +0000 (20:25 +0000)
Time/event.cxx
Time/event.hxx
Time/fg_time.cxx
Time/fg_time.hxx
Time/light.cxx
Time/sunpos.cxx
Time/sunpos.hxx
Time/timestamp.hxx

index 479438181dcec9c865bce8b55440557ad85e0f71..1126e03dc9d152c93adc10d40c533827950f7170 100644 (file)
 #  include <config.h>
 #endif
 
-#include <string.h>
-#include <stdio.h>
+#include <string>
 
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
+#include "Include/compiler.h"
+
+#include STL_ALGORITHM
+#include STL_FUNCTIONAL
+
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cstdio>
+#  ifdef HAVE_STDLIB_H
+#    include <cstdlib>
+#  endif
+#else
+#  include <stdio.h>
+#  ifdef HAVE_STDLIB_H
+#    include <stdlib.h>
+#  endif
 #endif
 
 #if defined( HAVE_WINDOWS_H ) && defined(__MWERKS__)
                          // 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 <Debug/logstream.hxx>
 
 #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<fgCallback>&)(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.
index c795b79a734ae792ebc07a84b9836fcb96fa9082..57d81e81de0b55dd1159452b97ccb4a46f1e9bd0 100644 (file)
 #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 <deque>        // STL double ended queue
 #include <list>         // STL list
 #include <string>
 
-#include "Include/fg_stl_config.h"
-
-#ifdef FG_NEED_AUTO_PTR
-#  include "Include/auto_ptr.hxx"
-#else
-#  include <memory>
-#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<fgCallback> 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.
index 4dbf4edd10e420bd9edce06074b2d6364b4501d4..24d130f13a05fe5578fcb81004cd32043b5ad316 100644 (file)
 #  include <config.h>
 #endif
 
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cmath>
+#  include <cstdio>
+#  include <cstdlib>
+#  include <ctime>
+#else
+#  include <math.h>
+#  include <stdio.h>
+#  include <stdlib.h>
+#  include <time.h>
+#endif
 
 #ifdef HAVE_SYS_TIMEB_H
 #  include <sys/timeb.h> // 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.
 //
index a308cdf1a8a9cc32c654337435e142b5f99c7fc2..979c2251b46f7478599c9ab99058a6b2dc2ea183 100644 (file)
 #endif
 
 #include <GL/glut.h>
-#include <time.h>
+
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <ctime>
+#else
+#  include <time.h>
+#endif
 
 #include <Flight/flight.hxx>
 
@@ -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.
 //
index 35f9b5708a5f3a509fc001e1e53ef1d2bd86d862..940a5960d7cc8b7e9be44af640dd012affe7ab50 100644 (file)
 #include <GL/glut.h>
 #include <XGL/xgl.h>
 
-#ifdef __BORLANDC__
+#include "Include/compiler.h"
+
+#ifdef FG_MATH_EXCEPTION_CLASH
 #  define exception c_exception
 #endif
-#include <math.h>
 
-#include <string.h>
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cmath>
+#else
+#  include <math.h>
+#endif
+
+#include <string>
+FG_USING_STD(string);
 
 #include <Aircraft/aircraft.hxx>
 #include <Debug/logstream.hxx>
@@ -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.
index cbe84f9204aa1efdd119ac0397009ecbbcb6a720..0a29b35a39120c8937b34cc408446a911e908ccb 100644 (file)
 #  include <config.h>
 #endif
 
-#include <math.h>
-#include <stdio.h>
-#include <time.h>
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cmath>
+#  include <cstdio>
+#  include <ctime>
+#else
+#  include <math.h>
+#  include <stdio.h>
+#  include <time.h>
+#endif
+
 
 //#include <Astro/orbits.hxx>
 #include <Astro/solarsystem.hxx>
@@ -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.
index 878dde13097104da7f10ede9d77c8abdaaa739a4..5ae3d0d7bcc9a4248562214d737313aa502f6611 100644 (file)
 # error This library requires C++
 #endif                                   
 
-
-#include <time.h>
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <ctime>
+#else
+#  include <time.h>
+#endif
 
 /* update the cur_time_params structure with the current sun position */
 void fgUpdateSunPos( void );
index c27eaefd57b4fe3129584728bff0b9ff24342244..42f8734d41bcf76ef4195f920f1457a0134266fd 100644 (file)
 #  include <windows.h>
 #endif
 
-#include <time.h>
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <ctime>
+#else
+#  include <time.h>
+#endif
 
 #ifdef HAVE_SYS_TIMEB_H
 #  include <sys/timeb.h> // 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.
 //