parameter.h

Go to the documentation of this file.
00001 /*
00002   $Id: parameter.h,v 1.3 2004/12/12 23:44:43 pecos Exp $
00003 */  
00004 
00005 /* *********
00006 *  
00007 *  This file is part of:
00008 *  NePSing, Network Protocol Simulator next generation
00009 *  
00010 *  Copyright (C) 2004  Tommaso Pecorella <tpecorella@mac.com>
00011 *  
00012 *  This library is free software; you can redistribute it and/or
00013 *  modify it under the terms of the GNU Lesser General Public
00014 *  License as published by the Free Software Foundation; either
00015 *  version 2.1 of the License, or (at your option) any later version.
00016 *  
00017 *  This library is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 *  Lesser General Public License for more details.
00021 *  
00022 *  You should have received a copy of the GNU Lesser General Public
00023 *  License along with this library; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *  
00026 ********* */
00027 
00028 #include <string>
00029 #include <map>
00030 #include <vector>
00031 #include <iostream>
00032 #include <iomanip>
00033 #include <list>
00034 #include <exception>
00035 
00036 using namespace std;  //introduces namespace std
00037 
00038 #ifndef ___PARAMETER_H___
00039 #define ___PARAMETER_H___
00040 
00041 
00089 
00097 #define READ_OK         0
00098 #define OPEN_FAIL       1
00099 #define UNEXPECTED_EOF  2
00100 #define UNKNOWN_PARAM   4
00101 
00102 #define MAX_LINE_LENGTH 256
00103 
00104 
00106 //
00107 class ParamManagerException : public exception
00108 {
00109   string Msg;
00110  public:
00111   ParamManagerException(const string &aMsg)
00112     : Msg(aMsg)
00113   {};
00114   virtual ~ParamManagerException() throw(){};
00115 
00116   virtual const char* what() const throw()
00117   {
00118     return (string(exception::what()) + Msg).c_str();
00119   };  
00120 };
00121 
00123 //
00124 class ParameterData
00125 {
00126  protected:
00127   string Value;
00128   string Class;
00129   string Instance;
00130 
00131  public:
00132   ParameterData();
00133   ParameterData(string aValue, string aClass, string aInstance);
00134 
00135   void getValue(const string &aClass, const string &aInstance, unsigned int &MatchLevel, string &aValue);
00136 
00137   bool operator==(const ParameterData& A);
00138 
00139   friend ostream& operator<< ( ostream& os, const ParameterData& par );
00140 };
00141 
00143 //
00144 
00146 class GenericParameter
00147 {
00148  protected:
00149   string Name;
00150   string Comment;
00151   string Default;
00152   string Values;
00153 
00154   list<ParameterData> Data;
00155   
00156   string getValue(const string &aClass, const string &aInstance);
00157 
00158   GenericParameter()
00159   {};
00160 
00161  public:
00162   GenericParameter(string aName, string aComment, string aDefault, string aValues);
00163 
00164   void setDefault(string aDefault);
00165 
00166   void addValue(string aValue, string aClass, string aInstance) throw(ParamManagerException);
00167 
00168   string getName();
00169 
00170   virtual ~GenericParameter();
00171 
00172   virtual void printTemplate(ostream& os, string Class, string Instance, 
00173                              bool Comments = true, bool CommentedOut = false);
00174 };
00175 
00177 //
00178 
00180 
00191 class IntParameter : public GenericParameter
00192 {
00193  public:
00195 
00201   IntParameter(string aName, string aComment, string aDefault, string aValues)
00202     : GenericParameter(aName, aComment, aDefault, aValues)
00203   {};
00204 
00206 
00210   int get(string aClass, string aInstance);
00211 };
00212 
00214 //
00215 
00217 
00228 class DoubleParameter : public GenericParameter
00229 {
00230  public:
00232 
00238   DoubleParameter(string aName, string aComment, string aDefault, string aValues)
00239     : GenericParameter(aName, aComment, aDefault, aValues)
00240   {};
00241 
00243 
00247   double get(string aClass, string aInstance);
00248 };
00249 
00251 //
00252 
00254 
00265 class StringParameter : public GenericParameter
00266 {
00267  public:
00269 
00275   StringParameter(string aName, string aComment, string aDefault, string aValues)
00276     : GenericParameter(aName, aComment, aDefault, aValues)
00277   {};
00278 
00280 
00284   string get(string aClass, string aInstance);
00285 };
00286 
00287 
00289 //
00290 
00292 
00306 class EnumParameter : public GenericParameter
00307 {
00308  protected:
00309   map<string, int> NameToValue;
00310   map<int, string> ValueToName;
00311 
00312  public:
00314 
00320     EnumParameter(string aName, 
00321                   string aComment, 
00322                   string aDefault, 
00323                   string aValues
00324                   );
00325 
00327 
00331   int get(string aClass, string aInstance);
00332 };
00333 
00335 //
00336 
00338 
00358 class BitmaskParameter : public GenericParameter
00359 {
00360  protected:
00361   map<string, int> NameToValue;
00362   map<int, string> ValueToName;
00363 
00364  public:
00366 
00374     BitmaskParameter(string aName, string aComment, string aDefault, string aValues);
00375   
00377 
00381   int get(string aClass, string aInstance);
00382 };
00383 
00385 
00386 #endif
00387 
00388 /*
00389 
00390   $Log: parameter.h,v $
00391   Revision 1.3  2004/12/12 23:44:43  pecos
00392   Added Copyright message - LGPL
00393 
00394   Revision 1.2  2004/12/11 23:53:24  pecos
00395   Added DoxyGen comments
00396 
00397   Revision 1.1.1.1  2004/07/08 16:59:33  pecos
00398   NePSing framework
00399 
00400   Revision 1.2  2000/10/22 19:44:27  pecos
00401   Removed some bugs about file parameter generation
00402 
00403   Revision 1.1.1.1  1999/05/24 15:59:57  inesis
00404   INeSiS Project
00405 
00406   Revision 1.1.1.1  1999/05/24 15:17:20  inesis
00407   INeSiS Project
00408 
00409 
00410 */

Generated on Wed Dec 22 23:23:47 2004 for NePSing by doxygen 1.3.9.1 ---- Hosted by SourceForge.net Logo