Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/factoryParams.cxx

Go to the documentation of this file.
00001 // Filename: factoryParams.cxx
00002 // Created by:  drose (08May00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "factoryParams.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: FactoryParams::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 FactoryParams::
00027 FactoryParams() {
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: FactoryParams::Destructor
00032 //       Access: Public
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 FactoryParams::
00036 ~FactoryParams() {
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: FactoryParams::add_param
00041 //       Access: Public
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 void FactoryParams::
00045 add_param(FactoryParam *param) {
00046   nassertv(param != (FactoryParam *)NULL);
00047   _params.push_back(param);
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////
00051 //     Function: FactoryParams::clear
00052 //       Access: Public
00053 //  Description: Removes all parameters from the set.
00054 ////////////////////////////////////////////////////////////////////
00055 void FactoryParams::
00056 clear() {
00057   _params.clear();
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: FactoryParams::get_num_params
00062 //       Access: Public
00063 //  Description: Returns the number of parameters that have been added
00064 //               to the set.
00065 ////////////////////////////////////////////////////////////////////
00066 int FactoryParams::
00067 get_num_params() const {
00068   return _params.size();
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: FactoryParams::get_param
00073 //       Access: Public
00074 //  Description: Returns the nth parameter that has been added to the
00075 //               set.
00076 ////////////////////////////////////////////////////////////////////
00077 FactoryParam *FactoryParams::
00078 get_param(int n) const {
00079   nassertr(n >= 0 && n < (int)_params.size(), NULL);
00080   return DCAST(FactoryParam, _params[n]);
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: FactoryParams::get_param_of_type
00085 //       Access: Public
00086 //  Description: Returns the first parameter that matches exactly the
00087 //               indicated type, or if there are no exact matches,
00088 //               returns the first one that derives from the indicated
00089 //               type.  If no parameters match at all, returns NULL.
00090 ////////////////////////////////////////////////////////////////////
00091 FactoryParam *FactoryParams::
00092 get_param_of_type(TypeHandle type) const {
00093   Params::const_iterator pi;
00094 
00095   // First, search for the exact match.
00096   for (pi = _params.begin(); pi != _params.end(); ++pi) {
00097     FactoryParam *param;
00098     DCAST_INTO_R(param, *pi, NULL);
00099     nassertr(param != (FactoryParam *)NULL, NULL);
00100 
00101     if (param->is_exact_type(type)) {
00102       return param;
00103     }
00104   }
00105 
00106   // Now, search for a derived match.
00107   for (pi = _params.begin(); pi != _params.end(); ++pi) {
00108     FactoryParam *param;
00109     DCAST_INTO_R(param, *pi, NULL);
00110     nassertr(param != (FactoryParam *)NULL, NULL);
00111 
00112     if (param->is_of_type(type)) {
00113       return param;
00114     }
00115   }
00116 
00117   return NULL;
00118 }

Generated on Fri May 2 00:43:38 2003 for Panda by doxygen1.3