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