parmanager.h

Go to the documentation of this file.
00001 /*
00002   $Id: parmanager.h,v 1.4 2004/12/17 10:10:27 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 <list>
00032 #include <typeinfo>
00033 
00034 #include "parameter.h"
00035 #include "misc.h"
00036 
00037 #ifndef ___PARMANAGER_H___
00038 #define ___PARMANAGER_H___
00039 
00040 
00041 #define READ_OK         0
00042 #define OPEN_FAIL       1
00043 #define UNEXPECTED_EOF  2
00044 #define UNKNOWN_PARAM   4
00045 
00046 #define MAX_LINE_LENGTH 256
00047 
00053 
00064 
00065 //
00066 class InstanceDesc
00067 {
00068  public:
00069   string Name;
00070   string Comment;
00071 
00072  public:
00073   InstanceDesc();
00074   InstanceDesc(string aName, string aComment);
00075 };
00076 
00078 //
00079 class ClassDesc
00080 {
00081  public:
00082   string Name;
00083   string Comment;
00084 
00085   list<int> Params;
00086   list<InstanceDesc> Instance;
00087   
00088  public:
00089   ClassDesc();
00090   ClassDesc(string aName, string aComment);
00091 };
00092 
00093 
00095 //
00096 
00098 
00105 class ParamManager
00106 {
00107  protected:
00108   vector<GenericParameter *> param;
00109   map<string, int> par_num;
00110 
00111   vector<ClassDesc> classes;
00112   map<string, int> classnum;
00113 
00114  public:
00115   // Constructor
00116   ParamManager();
00117 
00119 
00123   void addParameter(string Class, GenericParameter *aPar) throw(ParamManagerException);
00124 
00126 
00130   void addClass(string aClass, string aComment);
00131 
00133 
00138   void addInstance(string aClass, string aInstance, string aComment) throw(ParamManagerException);
00139 
00140 //  template<class parType, class outType> 
00141 //    outType get(string aName, string aClass, string aInstance);
00142 
00143   GenericParameter *get(string aName, string aClass, string aInstance) throw(ParamManagerException);
00144   
00146 
00150   void setDefault (string aName, string aValue) throw(ParamManagerException);
00151 
00152   void printTemplate(ostream &os, bool ClassComments, bool ParameterComments, bool ExpandInstances);
00153   
00154   // Reads parameters from the stream s
00155   void ReadFile(istream &s) throw(ParamManagerException);
00156 
00157   // Opens a file named FileName and calls ReadFile(istream &s) 
00158   void ReadFile(const char *FileName) throw(ParamManagerException);
00159 };
00160 
00161 template<class parType, class outType> 
00162   outType get(ParamManager* Param, string aName, string aClass, string aInstance) throw(ParamManagerException)
00163 {
00164   parType *p = dynamic_cast<parType *>(Param->get(aName, aClass, aInstance));
00165 
00166   if (!p)
00167   {
00168     throw ParamManagerException("Error getting parameter: " + aName + 
00169                                 " : parameter is not of type " + className(p) +
00170                                 " but of type " + className(Param->get(aName, aClass, aInstance)));
00171   }
00172   
00173   return p->get(aClass, aInstance);
00174 }
00175 
00177 
00178 #endif
00179 
00180 
00181 /*
00182 
00183   $Log: parmanager.h,v $
00184   Revision 1.4  2004/12/17 10:10:27  pecos
00185   No log message.
00186 
00187   Revision 1.3  2004/12/12 23:44:44  pecos
00188   Added Copyright message - LGPL
00189 
00190   Revision 1.2  2004/12/11 23:53:25  pecos
00191   Added DoxyGen comments
00192 
00193   Revision 1.1.1.1  2004/07/08 16:59:33  pecos
00194   NePSing framework
00195 
00196   Revision 1.1.1.1  1999/05/24 15:59:57  inesis
00197   INeSiS Project
00198 
00199   Revision 1.1.1.1  1999/05/24 15:17:20  inesis
00200   INeSiS Project
00201 
00202 
00203 */

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