Panda3D

configVariableCore.h

00001 // Filename: configVariableCore.h
00002 // Created by:  drose (15Oct04)
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 #ifndef CONFIGVARIABLECORE_H
00016 #define CONFIGVARIABLECORE_H
00017 
00018 #include "dtoolbase.h"
00019 #include "configFlags.h"
00020 #include "configPageManager.h"
00021 #include "pnotify.h"
00022 
00023 #include <vector>
00024 
00025 class ConfigDeclaration;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : ConfigVariableCore
00029 // Description : The internal definition of a ConfigVariable.  This
00030 //               object is shared between all instances of a
00031 //               ConfigVariable that use the same variable name.
00032 //
00033 //               You cannot create a ConfigVariableCore instance
00034 //               directly; instead, use the make() method, which may
00035 //               return a shared instance.  Once created, these
00036 //               objects are never destructed.
00037 ////////////////////////////////////////////////////////////////////
00038 class EXPCL_DTOOLCONFIG ConfigVariableCore : public ConfigFlags {
00039 private:
00040   ConfigVariableCore(const string &name);
00041   ConfigVariableCore(const ConfigVariableCore &templ, const string &name);
00042   ~ConfigVariableCore();
00043 
00044 PUBLISHED:
00045   INLINE const string &get_name() const;
00046   INLINE bool is_used() const;
00047 
00048   INLINE ValueType get_value_type() const;
00049   INLINE const string &get_description() const;
00050   INLINE int get_flags() const;
00051   INLINE bool is_closed() const;
00052   INLINE int get_trust_level() const;
00053   INLINE bool is_dynamic() const;
00054   INLINE const ConfigDeclaration *get_default_value() const;
00055 
00056   void set_value_type(ValueType value_type);
00057   void set_flags(int flags);
00058   void set_description(const string &description);
00059   void set_default_value(const string &default_value);
00060   INLINE void set_used();
00061 
00062   ConfigDeclaration *make_local_value();
00063   bool clear_local_value();
00064   INLINE bool has_local_value() const;
00065 
00066   bool has_value() const;
00067   int get_num_declarations() const;
00068   const ConfigDeclaration *get_declaration(int n) const;
00069 
00070   INLINE int get_num_references() const;
00071   INLINE const ConfigDeclaration *get_reference(int n) const;
00072 
00073   INLINE int get_num_trusted_references() const;
00074   INLINE const ConfigDeclaration *get_trusted_reference(int n) const;
00075 
00076   INLINE int get_num_unique_references() const;
00077   INLINE const ConfigDeclaration *get_unique_reference(int n) const;
00078 
00079   void output(ostream &out) const;
00080   void write(ostream &out) const;
00081 
00082 private:
00083   void add_declaration(ConfigDeclaration *decl);
00084   void remove_declaration(ConfigDeclaration *decl);
00085 
00086   INLINE void check_sort_declarations() const;
00087   void sort_declarations();
00088 
00089 private:
00090   string _name;
00091   bool _is_used;
00092   ValueType _value_type;
00093   string _description;
00094   int _flags;
00095   ConfigDeclaration *_default_value;
00096   ConfigDeclaration *_local_value;
00097 
00098   typedef vector<const ConfigDeclaration *> Declarations;
00099   Declarations _declarations;
00100   Declarations _trusted_declarations;
00101   Declarations _untrusted_declarations;
00102   Declarations _unique_declarations;
00103   bool _declarations_sorted;
00104   bool _value_queried;
00105 
00106   friend class ConfigDeclaration;
00107   friend class ConfigVariableManager;
00108 };
00109 
00110 INLINE ostream &operator << (ostream &out, const ConfigVariableCore &variable);
00111 
00112 #include "configVariableCore.I"
00113 
00114 #endif
 All Classes Functions Variables Enumerations