Panda3D
 All Classes Functions Variables Enumerations
configVariableBase.cxx
00001 // Filename: configVariableBase.cxx
00002 // Created by:  drose (21Oct04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "configVariableBase.h"
00016 
00017 ConfigVariableBase::Unconstructed *ConfigVariableBase::_unconstructed;
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: ConfigVariableBase::Constructor
00021 //       Access: Protected
00022 //  Description: This constructor is only intended to be called from a
00023 //               specialized ConfigVariableFoo derived class.
00024 ////////////////////////////////////////////////////////////////////
00025 ConfigVariableBase::
00026 ConfigVariableBase(const string &name, 
00027                    ConfigVariableBase::ValueType value_type,
00028                    const string &description, int flags) :
00029   _core(ConfigVariableManager::get_global_ptr()->make_variable(name))
00030 {
00031 #ifndef NDEBUG
00032   if (was_unconstructed()) {
00033     prc_cat->error()
00034       << "Late constructing " << this << ": " << name << "\n";
00035   }
00036 #endif  // NDEBUG
00037 
00038   if (value_type != VT_undefined) {
00039     _core->set_value_type(value_type);
00040   }
00041 #ifdef PRC_SAVE_DESCRIPTIONS
00042   if (!description.empty()) {
00043     _core->set_description(description);
00044   }
00045 #endif  // PRC_SAVE_DESCRIPTIONS
00046   if (flags != 0) {
00047     _core->set_flags(flags);
00048   }
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: ConfigVariableBase::record_unconstructed
00053 //       Access: Protected
00054 //  Description: Records that this config variable was referenced
00055 //               before it was constructed (presumably a static-init
00056 //               ordering issue).  This is used to print a useful
00057 //               error message later, when the constructor is actually
00058 //               called (and we then know what the name of the
00059 //               variable is).
00060 ////////////////////////////////////////////////////////////////////
00061 void ConfigVariableBase::
00062 record_unconstructed() const {
00063 #ifndef NDEBUG
00064   if (_unconstructed == (Unconstructed *)NULL) {
00065     _unconstructed = new Unconstructed;
00066   }
00067   _unconstructed->insert(this);
00068 #endif
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: ConfigVariableBase::was_unconstructed
00073 //       Access: Protected
00074 //  Description: Returns true if record_unconstructed() was ever
00075 //               called on this pointer, false otherwise.
00076 ////////////////////////////////////////////////////////////////////
00077 bool ConfigVariableBase::
00078 was_unconstructed() const {
00079 #ifndef NDEBUG
00080   if (_unconstructed != (Unconstructed *)NULL) {
00081     Unconstructed::const_iterator ui = _unconstructed->find(this);
00082     if (ui != _unconstructed->end()) {
00083       return true;
00084     }
00085   }
00086 #endif
00087   return false;
00088 }
00089 
 All Classes Functions Variables Enumerations