OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FacWorld.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // C
5 #include <assert.h>
6 // OPENTREP
8 #include <opentrep/bom/World.hpp>
9 #include <opentrep/bom/Place.hpp>
15 
16 namespace OPENTREP {
17 
18  FacWorld* FacWorld::_instance = NULL;
19 
20  // //////////////////////////////////////////////////////////////////////
22  _instance = NULL;
23  }
24 
25  // //////////////////////////////////////////////////////////////////////
27 
28  if (_instance == NULL) {
29  _instance = new FacWorld();
30  assert (_instance != NULL);
31 
33  }
34  return *_instance;
35  }
36 
37  // //////////////////////////////////////////////////////////////////////
39  World* oWorld_ptr = NULL;
40 
41  oWorld_ptr = new World ();
42  assert (oWorld_ptr != NULL);
43 
44  // The new object is added to the Bom pool
45  _pool.push_back (oWorld_ptr);
46 
47  return *oWorld_ptr;
48  }
49 
50  // //////////////////////////////////////////////////////////////////////
51  void FacWorld::linkPlaceToWorld (const bool iNeedsGeneric,
52  World& ioWorld, Place& ioPlace) {
53  // Link the World to the Place, and vice versa
54  ioPlace._world = &ioWorld;
55 
56  // Retrieve the Xapian document ID of the Place object
57  const XapianDocID_T& lDocID = ioPlace.getDocID();
58 
59  // Build a generic BOM object
60  const GenericBom_T lGenericBom (BomType::PLACE, &ioPlace);
61 
62  if (iNeedsGeneric == true) {
63  // Add the Place pointer to the dedicated list within the World object
64  const bool insertSucceeded = ioWorld._genericBomList.
65  insert (GenericBomList_T::value_type (lDocID, lGenericBom)).second;
66  if (insertSucceeded == false) {
67  OPENTREP_LOG_ERROR ("Insertion failed for " << ioWorld.describeKey()
68  << " and " << ioPlace.describeShortKey());
69  assert (insertSucceeded == true);
70  }
71 
72  // Add the Place pointer to the dedicated list within the World object
73  /*
74  const bool insertSucceeded2 = ioWorld._placeDirectList.
75  insert (PlaceDirectList_T::value_type (lPlaceID, &ioPlace)).second;
76  if (insertSucceeded2 == false) {
77  OPENTREP_LOG_ERROR ("Insertion failed for " << ioWorld.describeKey()
78  << " and " << ioPlace.describeShortKey());
79  assert (insertSucceeded2 == true);
80  }
81  */
82 
83  }
84 
85  // Add the Place pointer to the dedicated list within the World object
86  ioWorld._placeOrderedList.push_back (&ioPlace);
87  }
88 
89  // //////////////////////////////////////////////////////////////////////
90  World& FacWorld::clone (const World& iWorld) {
91  World* oWorld_ptr = NULL;
92 
93  oWorld_ptr = new World (iWorld);
94  assert (oWorld_ptr != NULL);
95 
96  // The new object is added to the Bom pool
97  _pool.push_back (oWorld_ptr);
98 
99  return *oWorld_ptr;
100  }
101 
102 }
std::pair< BomType::EN_BomType, BomAbstract * > GenericBom_T
Definition: GenericBom.hpp:15
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:23
static FacSupervisor & instance()
static FacWorld & instance()
Definition: FacWorld.cpp:26
World & create()
Definition: FacWorld.cpp:38
std::string describeShortKey() const
Definition: Place.hpp:1009
void registerBomFactory(FacBomAbstract *)
std::string describeKey() const
Definition: World.cpp:34
Class modelling a place/POR (point of reference).
Definition: Place.hpp:28
const XapianDocID_T & getDocID() const
Definition: Place.hpp:445
virtual ~FacWorld()
Definition: FacWorld.cpp:21
static void linkPlaceToWorld(const bool iNeedsGeneric, World &, Place &)
Definition: FacWorld.cpp:51
World & clone(const World &)
Definition: FacWorld.cpp:90