Panda3D
 All Classes Functions Variables Enumerations
factoryParams.cxx
00001 // Filename: factoryParams.cxx
00002 // Created by:  drose (08May00)
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 "factoryParams.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: FactoryParams::Constructor
00019 //       Access: Public
00020 //  Description:
00021 ////////////////////////////////////////////////////////////////////
00022 FactoryParams::
00023 FactoryParams() {
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: FactoryParams::Destructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 FactoryParams::
00032 ~FactoryParams() {
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: FactoryParams::add_param
00037 //       Access: Public
00038 //  Description:
00039 ////////////////////////////////////////////////////////////////////
00040 void FactoryParams::
00041 add_param(FactoryParam *param) {
00042   nassertv(param != (FactoryParam *)NULL);
00043   _params.push_back(param);
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: FactoryParams::clear
00048 //       Access: Public
00049 //  Description: Removes all parameters from the set.
00050 ////////////////////////////////////////////////////////////////////
00051 void FactoryParams::
00052 clear() {
00053   _params.clear();
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: FactoryParams::get_num_params
00058 //       Access: Public
00059 //  Description: Returns the number of parameters that have been added
00060 //               to the set.
00061 ////////////////////////////////////////////////////////////////////
00062 int FactoryParams::
00063 get_num_params() const {
00064   return _params.size();
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: FactoryParams::get_param
00069 //       Access: Public
00070 //  Description: Returns the nth parameter that has been added to the
00071 //               set.
00072 ////////////////////////////////////////////////////////////////////
00073 FactoryParam *FactoryParams::
00074 get_param(int n) const {
00075   nassertr(n >= 0 && n < (int)_params.size(), NULL);
00076   return DCAST(FactoryParam, _params[n]);
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: FactoryParams::get_param_of_type
00081 //       Access: Public
00082 //  Description: Returns the first parameter that matches exactly the
00083 //               indicated type, or if there are no exact matches,
00084 //               returns the first one that derives from the indicated
00085 //               type.  If no parameters match at all, returns NULL.
00086 ////////////////////////////////////////////////////////////////////
00087 FactoryParam *FactoryParams::
00088 get_param_of_type(TypeHandle type) const {
00089   Params::const_iterator pi;
00090 
00091   // First, search for the exact match.
00092   for (pi = _params.begin(); pi != _params.end(); ++pi) {
00093     FactoryParam *param;
00094     DCAST_INTO_R(param, *pi, NULL);
00095     nassertr(param != (FactoryParam *)NULL, NULL);
00096 
00097     if (param->is_exact_type(type)) {
00098       return param;
00099     }
00100   }
00101 
00102   // Now, search for a derived match.
00103   for (pi = _params.begin(); pi != _params.end(); ++pi) {
00104     FactoryParam *param;
00105     DCAST_INTO_R(param, *pi, NULL);
00106     nassertr(param != (FactoryParam *)NULL, NULL);
00107 
00108     if (param->is_of_type(type)) {
00109       return param;
00110     }
00111   }
00112 
00113   return NULL;
00114 }
 All Classes Functions Variables Enumerations