diff --git a/dtool/src/prc/Sources.pp b/dtool/src/prc/Sources.pp index c5d98b256e..e0f11d6fcf 100644 --- a/dtool/src/prc/Sources.pp +++ b/dtool/src/prc/Sources.pp @@ -16,6 +16,7 @@ configVariableCore.cxx configVariableCore.I configVariableCore.h \ configVariableDouble.cxx configVariableDouble.I configVariableDouble.h \ configVariableEnum.cxx configVariableEnum.I configVariableEnum.h \ + configVariableFilename.cxx configVariableFilename.I configVariableFilename.h \ configVariableInt.cxx configVariableInt.I configVariableInt.h \ configVariableList.cxx configVariableList.I configVariableList.h \ configVariableManager.cxx configVariableManager.I configVariableManager.h \ @@ -40,6 +41,7 @@ configVariableCore.I configVariableCore.h \ configVariableDouble.I configVariableDouble.h \ configVariableEnum.I configVariableEnum.h \ + configVariableFilename.I configVariableFilename.h \ configVariableInt.I configVariableInt.h \ configVariableList.I configVariableList.h \ configVariableManager.I configVariableManager.h \ diff --git a/dtool/src/prc/configFlags.cxx b/dtool/src/prc/configFlags.cxx index 9660a9fcc1..2f5a7be3e7 100644 --- a/dtool/src/prc/configFlags.cxx +++ b/dtool/src/prc/configFlags.cxx @@ -34,6 +34,9 @@ operator << (ostream &out, ConfigFlags::ValueType type) { case ConfigFlags::VT_string: return out << "string"; + case ConfigFlags::VT_filename: + return out << "filename"; + case ConfigFlags::VT_bool: return out << "bool"; diff --git a/dtool/src/prc/configFlags.h b/dtool/src/prc/configFlags.h index c8202f8ebc..742a99cebf 100644 --- a/dtool/src/prc/configFlags.h +++ b/dtool/src/prc/configFlags.h @@ -34,6 +34,7 @@ PUBLISHED: VT_undefined, VT_list, VT_string, + VT_filename, VT_bool, VT_int, VT_double, diff --git a/dtool/src/prc/configVariableFilename.I b/dtool/src/prc/configVariableFilename.I new file mode 100644 index 0000000000..767a9e0a10 --- /dev/null +++ b/dtool/src/prc/configVariableFilename.I @@ -0,0 +1,159 @@ +// Filename: configVariableFilename.I +// Created by: drose (22Nov04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ConfigVariableFilename:: +ConfigVariableFilename(const string &name) : + ConfigVariable(name, VT_filename) +{ + _core->set_used(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ConfigVariableFilename:: +ConfigVariableFilename(const string &name, const Filename &default_value, + const string &description, int flags) : + ConfigVariable(name, VT_filename, description, flags) +{ + _core->set_default_value(default_value); + _core->set_used(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::operator = +// Access: Published +// Description: Reassigns the variable's local value. +//////////////////////////////////////////////////////////////////// +INLINE void ConfigVariableFilename:: +operator = (const Filename &value) { + set_value(value); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Filename typecast operator +// Access: Published +// Description: Returns the variable's value as a Filename. +//////////////////////////////////////////////////////////////////// +INLINE ConfigVariableFilename:: +operator Filename () const { + return get_value(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::empty +// Access: Published +// Description: Returns true if the filename is empty, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool ConfigVariableFilename:: +empty() const { + return get_value().empty(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Equality operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool ConfigVariableFilename:: +operator == (const Filename &other) const { + return get_value() == other; +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Inequality operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool ConfigVariableFilename:: +operator != (const Filename &other) const { + return get_value() != other; +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::Ordering operator +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool ConfigVariableFilename:: +operator < (const Filename &other) const { + return get_value() < other; +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::set_value +// Access: Published +// Description: Reassigns the variable's local value. +//////////////////////////////////////////////////////////////////// +INLINE void ConfigVariableFilename:: +set_value(const Filename &value) { + set_string_value(value); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::get_value +// Access: Published +// Description: Returns the variable's value. +//////////////////////////////////////////////////////////////////// +INLINE Filename ConfigVariableFilename:: +get_value() const { + return Filename::expand_from(get_string_value()); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::get_default_value +// Access: Published +// Description: Returns the variable's default value. +//////////////////////////////////////////////////////////////////// +INLINE Filename ConfigVariableFilename:: +get_default_value() const { + const ConfigDeclaration *decl = ConfigVariable::get_default_value(); + if (decl != (ConfigDeclaration *)NULL) { + return decl->get_string_word(0); + } + return string(); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::get_word +// Access: Published +// Description: Returns the variable's nth value. +//////////////////////////////////////////////////////////////////// +INLINE Filename ConfigVariableFilename:: +get_word(int n) const { + return Filename::expand_from(get_string_word(n)); +} + +//////////////////////////////////////////////////////////////////// +// Function: ConfigVariableFilename::set_word +// Access: Published +// Description: Reassigns the variable's nth value. This makes a +// local copy of the variable's overall value. +//////////////////////////////////////////////////////////////////// +INLINE void ConfigVariableFilename:: +set_word(int n, const Filename &value) { + set_string_word(n, value); +} diff --git a/dtool/src/prc/configVariableFilename.cxx b/dtool/src/prc/configVariableFilename.cxx new file mode 100644 index 0000000000..efcd06b73a --- /dev/null +++ b/dtool/src/prc/configVariableFilename.cxx @@ -0,0 +1,19 @@ +// Filename: configVariableFilename.cxx +// Created by: drose (22Nov04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "configVariableFilename.h" diff --git a/dtool/src/prc/configVariableFilename.h b/dtool/src/prc/configVariableFilename.h new file mode 100644 index 0000000000..386ce53d6f --- /dev/null +++ b/dtool/src/prc/configVariableFilename.h @@ -0,0 +1,60 @@ +// Filename: configVariableFilename.h +// Created by: drose (22Nov04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#ifndef CONFIGVARIABLEFILENAME_H +#define CONFIGVARIABLEFILENAME_H + +#include "dtoolbase.h" +#include "configVariable.h" +#include "filename.h" + +//////////////////////////////////////////////////////////////////// +// Class : ConfigVariableFilename +// Description : This is a convenience class to specialize +// ConfigVariable as a Filename type. It is almost the +// same thing as ConfigVariableString, except it handles +// an implicit Filename::expand_from() operation so that +// the user may put OS-specific filenames, or filenames +// based on environment variables, in the prc file. +//////////////////////////////////////////////////////////////////// +class EXPCL_DTOOLCONFIG ConfigVariableFilename : public ConfigVariable { +PUBLISHED: + INLINE ConfigVariableFilename(const string &name); + INLINE ConfigVariableFilename(const string &name, const Filename &default_value, + const string &description = string(), int flags = 0); + + INLINE void operator = (const Filename &value); + INLINE operator Filename () const; + INLINE bool empty() const; + + // Comparison operators are handy. + INLINE bool operator == (const Filename &other) const; + INLINE bool operator != (const Filename &other) const; + INLINE bool operator < (const Filename &other) const; + + INLINE void set_value(const Filename &value); + INLINE Filename get_value() const; + INLINE Filename get_default_value() const; + + INLINE Filename get_word(int n) const; + INLINE void set_word(int n, const Filename &value); +}; + +#include "configVariableFilename.I" + +#endif diff --git a/dtool/src/prc/configVariableString.I b/dtool/src/prc/configVariableString.I index 070e290d86..ebcc426477 100644 --- a/dtool/src/prc/configVariableString.I +++ b/dtool/src/prc/configVariableString.I @@ -35,7 +35,7 @@ ConfigVariableString(const string &name) : // Description: //////////////////////////////////////////////////////////////////// INLINE ConfigVariableString:: -ConfigVariableString(const string &name, string default_value, +ConfigVariableString(const string &name, const string &default_value, const string &description, int flags) : ConfigVariable(name, VT_string, description, flags) { @@ -63,19 +63,6 @@ operator string () const { return get_value(); } -//////////////////////////////////////////////////////////////////// -// Function: ConfigVariableString::Filename typecast operator -// Access: Published -// Description: Returns the variable's value. This typecast operator -// is a convenience in case you happen to want to assign -// a ConfigVariableString into a Filename; C++ won't -// make the implicit typecast for you. -//////////////////////////////////////////////////////////////////// -INLINE ConfigVariableString:: -operator Filename () const { - return get_value(); -} - //////////////////////////////////////////////////////////////////// // Function: ConfigVariableString::empty // Access: Published diff --git a/dtool/src/prc/configVariableString.h b/dtool/src/prc/configVariableString.h index e848ac9230..6c85b09934 100644 --- a/dtool/src/prc/configVariableString.h +++ b/dtool/src/prc/configVariableString.h @@ -21,7 +21,6 @@ #include "dtoolbase.h" #include "configVariable.h" -#include "filename.h" //////////////////////////////////////////////////////////////////// // Class : ConfigVariableString @@ -31,12 +30,11 @@ class EXPCL_DTOOLCONFIG ConfigVariableString : public ConfigVariable { PUBLISHED: INLINE ConfigVariableString(const string &name); - INLINE ConfigVariableString(const string &name, string default_value, + INLINE ConfigVariableString(const string &name, const string &default_value, const string &description = string(), int flags = 0); INLINE void operator = (const string &value); INLINE operator string () const; - INLINE operator Filename () const; INLINE bool empty() const; // Comparison operators are handy. diff --git a/dtool/src/prc/notify.cxx b/dtool/src/prc/notify.cxx index 42a385290b..489e6df468 100644 --- a/dtool/src/prc/notify.cxx +++ b/dtool/src/prc/notify.cxx @@ -19,7 +19,7 @@ #include "notify.h" #include "notifyCategory.h" #include "configPageManager.h" -#include "configVariableString.h" +#include "configVariableFilename.h" #include "configVariableBool.h" #include "filename.h" @@ -527,7 +527,7 @@ config_initialized() { already_initialized = true; if (_ostream_ptr == &cerr) { - ConfigVariableString notify_output + ConfigVariableFilename notify_output ("notify-output", "", "The filename to which to write all the output of notify"); diff --git a/panda/src/doc/howto.use_config.txt b/panda/src/doc/howto.use_config.txt index 0e92ce527d..f4d59a4c7e 100644 --- a/panda/src/doc/howto.use_config.txt +++ b/panda/src/doc/howto.use_config.txt @@ -89,6 +89,7 @@ ConfigVariableString ConfigVariableBool ConfigVariableInt ConfigVariableDouble +ConfigVariableFilename ConfigVariableEnum (C++ only) ConfigVariableList ConfigVariableSearchPath @@ -96,9 +97,19 @@ ConfigVariableSearchPath These each define a config variable of the corresponding type. For instance, a ConfigVariableInt defines a variable whose value must always be an integer value. The most common variable types are the -top four, which are self-explanatory; the remaining three are special +top four, which are self-explanatory; the remaining four are special types: +ConfigVariableFilename - + + This is a convenience class which behaves very much like a + ConfigVariableString, except that it automatically converts from + OS-specific filenames that may be given in the prc file to + Panda-specific filenames, and it also automatically expands + environment variable references, so that the user may name a file + based on the value of an environment variable + (e.g. $PANDAMODELS/file.egg). + ConfigVariableEnum - This is a special template class available in C++ only. It provides