NMPB08 Shared Libraries
RailwayDatabase.h
Go to the documentation of this file.
00001 #ifndef _RAILWAYDATABASE_INCLUDED_
00002 #define _RAILWAYDATABASE_INCLUDED_
00003 
00004 #include "RailwayEmissionNMPB08.h"
00005 #include "../LectureXML/LectureXML.hpp"
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009 #include <assert.h>
00010 
00011 // ----------------------------------------------------------------------------------
00016 typedef std::string IDREF ;
00017 
00018 // ----------------------------------------------------------------------------------
00025 // on Unix-like systems there is no way to hide local classes ant to prevent them from 
00026 // being replaced by other classes with similar names in other libraries. The use of 
00027 // unusual names may help preventing name clashes.
00028 
00029 #ifndef _WIN32
00030 #define Spectrum                                _Local_RWDBN8_Spectrum_
00031 #define RailwaySource                   _Local_RWDBN8_RailwaySource_
00032 #define RailwaySourcePosition   _Local_RWDBN8_SourcePosition_
00033 #define RailwayUnit                             _Local_RWDBN8_RailwayUnit_
00034 #define RailwayTrainUnit                _Local_RWDBN8_RailwayTrainUnit_
00035 #define RailwayTrain                    _Local_RWDBN8_RailwayTrain_
00036 #define RailwayDatabase                 _Local_RWDBN8_RailwayDatabase_
00037 #endif
00038 
00039 struct Spectrum : public std::vector<double>
00040 {
00041         Spectrum(void) //: std::vector<double>() 
00042         { 
00043                 resize (18, 0.0) ; 
00044         }
00045         Spectrum (Spectrum const& other) : std::vector<double> (other) 
00046         {
00047                 assert (size() == 18) ;
00048         }
00049 } ;
00050 
00051 
00052 //typedef double Spectrum[18] ;
00053 
00054 // ----------------------------------------------------------------------------------
00060 struct RailwaySource
00061 {
00062         double          height ;                
00063         double          vref ;                  
00064         double          slope ;                 
00065         int                     hdir_model ;    
00066         int                     vdir_model ;    
00067         Spectrum        Lw ;                    
00069         RailwaySource (void) 
00070         : height(), vref(), slope(), hdir_model(), vdir_model(), Lw()
00071         {
00072         }
00073 } ;
00074 
00075 // ----------------------------------------------------------------------------------
00080 struct RailwaySourcePosition
00081 {
00082         IDREF           ref ;           
00083         int                     nb ;            
00084         double          pos ;           
00085         double          spacing ;       
00087         RailwaySourcePosition(void) : ref(),nb(),pos(),spacing() {}
00088 } ;
00089 
00090 // ----------------------------------------------------------------------------------
00095 struct RailwayUnit
00096 {
00097         std::string  name ;                     
00098         double           length ;               
00099         std::string  image ;            
00100         double           vmax ;                 
00101         double           cref ;                 
00102         bool             part_of_train ;        
00103         std::vector<RailwaySourcePosition> source ; 
00105         RailwayUnit (void)
00106                 : name(), length(), image(), vmax(), cref(), part_of_train(), source()  { }
00107 } ;
00108 
00109 // ----------------------------------------------------------------------------------
00113 struct RailwayTrainUnit
00114 {
00115         IDREF   ref ;   
00116         int             nb ;    
00118         RailwayTrainUnit(void) : ref(), nb() { }
00119 } ;
00120 
00121 // ----------------------------------------------------------------------------------
00126 struct RailwayTrain
00127 {
00128         std::string  name ;             
00129         std::string  image ;    
00130         std::vector<RailwayTrainUnit> unit ; 
00132         RailwayTrain (void) 
00133                 : name(), image(), unit()       { }
00134 } ;
00135 
00136 // ----------------------------------------------------------------------------------
00147 class RailwayDatabase
00148 {
00149 public:
00150 
00151         RailwayDatabase(void)
00152                 : unit_map(), source_map(), train_map(), trace_debug(), error_code() { }
00153 
00159         int LoadFile (const char* filename, bool trace = false) ;
00160 
00163         int GetErrorCode (void) { return error_code ; }
00164 
00169         int Dump (const char* filename) ;
00170 
00177         int EnumEntities (EnumRailwayEntities enumProc, 
00178                                           unsigned int include_types,
00179                                           void* userdata) ;
00180 
00188         int EnumSources (EnumRailwaySources enumProc,
00189                                          IDREF id, 
00190                                          void* userdata,
00191                                          double pos = 0.0) ;
00192 
00196         RailwaySource const* getSource (IDREF ref) ;
00197 
00201         RailwayUnit   const* getUnit (IDREF ref) ;
00202 
00206         RailwayTrain  const* getTrain (IDREF ref) ;
00207 
00208 private:
00209 
00211         bool ParseUnit (XMLNode* child) ;
00212 
00214         bool ParseTrain (XMLNode* child) ;
00215 
00217         bool ParseSource (XMLNode* child) ;
00218 
00220         bool ParseSourcePosition (XMLNode* child, RailwaySourcePosition& pos) ;
00221 
00223         bool ParseTrainUnit(XMLNode* child, RailwayTrainUnit& unit) ;
00224 
00226         typedef std::map<IDREF, RailwaySource>  SourceMap ;
00227 
00229         typedef std::map<IDREF, RailwayUnit>    UnitMap ;
00230 
00232         typedef std::map<IDREF, RailwayTrain>   TrainMap ;
00233 
00235         UnitMap         unit_map ;
00236 
00238         SourceMap       source_map ;
00239 
00241         TrainMap        train_map ;
00242 
00244         bool    trace_debug ;
00245 
00247         int             error_code ;
00248 } ;
00249 
00250 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines