Panda3D
configVariableBase.cxx
1 // Filename: configVariableBase.cxx
2 // Created by: drose (21Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "configVariableBase.h"
16 #include "config_prc.h"
17 
18 ConfigVariableBase::Unconstructed *ConfigVariableBase::_unconstructed;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: ConfigVariableBase::Constructor
22 // Access: Protected
23 // Description: This constructor is only intended to be called from a
24 // specialized ConfigVariableFoo derived class.
25 ////////////////////////////////////////////////////////////////////
26 ConfigVariableBase::
27 ConfigVariableBase(const string &name,
28  ConfigVariableBase::ValueType value_type,
29  const string &description, int flags) :
30  _core(ConfigVariableManager::get_global_ptr()->make_variable(name))
31 {
32 #ifndef NDEBUG
33  if (was_unconstructed()) {
34  prc_cat->error()
35  << "Late constructing " << this << ": " << name << "\n";
36  }
37 #endif // NDEBUG
38 
39  if (value_type != VT_undefined) {
40  _core->set_value_type(value_type);
41  }
42 #ifdef PRC_SAVE_DESCRIPTIONS
43  if (!description.empty()) {
44  _core->set_description(description);
45  }
46 #endif // PRC_SAVE_DESCRIPTIONS
47  if (flags != 0) {
48  _core->set_flags(flags);
49  }
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: ConfigVariableBase::record_unconstructed
54 // Access: Protected
55 // Description: Records that this config variable was referenced
56 // before it was constructed (presumably a static-init
57 // ordering issue). This is used to print a useful
58 // error message later, when the constructor is actually
59 // called (and we then know what the name of the
60 // variable is).
61 ////////////////////////////////////////////////////////////////////
62 void ConfigVariableBase::
63 record_unconstructed() const {
64 #ifndef NDEBUG
65  if (_unconstructed == (Unconstructed *)NULL) {
66  _unconstructed = new Unconstructed;
67  }
68  _unconstructed->insert(this);
69 #endif
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: ConfigVariableBase::was_unconstructed
74 // Access: Protected
75 // Description: Returns true if record_unconstructed() was ever
76 // called on this pointer, false otherwise.
77 ////////////////////////////////////////////////////////////////////
78 bool ConfigVariableBase::
79 was_unconstructed() const {
80 #ifndef NDEBUG
81  if (_unconstructed != (Unconstructed *)NULL) {
82  Unconstructed::const_iterator ui = _unconstructed->find(this);
83  if (ui != _unconstructed->end()) {
84  return true;
85  }
86  }
87 #endif
88  return false;
89 }
90 
A global object that maintains the set of ConfigVariables (actually, ConfigVariableCores) everywhere ...
This is our own Panda specialization on the default STL set.
Definition: pset.h:52