Overture  Version 25
NameList.h
Go to the documentation of this file.
1 #ifndef NAMELIST_H
2 #define NAMELIST_H "NameList.h"
3 
4 #include "GenericDataBase.h"
5 #include <A++.h>
6 #include "aString.H"
7 #include <string.h>
8 #include "OvertureTypes.h"
9 
10 //=============================================================================
11 // This class defines routines for inputing Parameters by name
12 // in a similar fashion to the namelist facility in Fortran
13 //
14 // Suppose that an application has a list of variables that can
15 // be changed by the user. Also suppose that the variables have
16 // default values so that the user may only want to selectively
17 // change the values of some variables
18 //
19 // Here is how the application could prompt for changes using the
20 // NameList class:
21 //
22 // int itest=0, imeth=3; // Here are some parameters
23 // real a=1.,b=2.;
24 // IntegerArray c(3,3,3); c=0.;
25 // RealArray d(4,4,4); d=1.;
26 //
27 // NameList nl; // create a namelist
28 //
29 // aString answer(80),name(80);
30 // int i0,i1,i2,i3;
31 // for( ;; )
32 // {
33 // cout << "Enter changes to variables, exit to continue" << endl;
34 // cin >> answer;
35 // if( answer=="exit" ) break;
36 //
37 // nl.getVariableName( answer, name ); // parse the answer
38 // if( name=="itest" )
39 // itest=nl.intValue(answer);
40 // else if( name=="imeth" )
41 // imeth=nl.intValue(answer);
42 // else if( name=="a" )
43 // a=nl.realValue(answer);
44 // else if( name=="b" )
45 // b=nl.realValue(answer);
46 // else if( name=="c" )
47 // nl.getIntArray( answer,c );
48 // else if( name=="d" )
49 // nl.getRealArray( answer,d,i0,i1,i2 ); // return indices as well
50 // else
51 // cout << "unknown response: [" << name << "]" << endl;
52 // }
53 //
54 //
55 // Here is some typical input:
56 //
57 // itest=1
58 // c(1,0,1)=55
59 // a=55.6
60 // d(1,1,2)=33.3
61 // exit
62 //
63 //============================================================================
64 class NameList
65 {
66  public:
67 
68  NameList();
69  ~NameList();
70 
71  void getVariableName( aString & answer, aString & name );
72 
73  int intValue( aString & answer );
74 
75  // add float and double ****************************************************
76  real realValue( aString & answer );
77 
78  int getIntArray( aString & answer, IntegerArray & a );
79  int getIntArray( aString & answer, IntegerArray & a, int & i0 );
80  int getIntArray( aString & answer, IntegerArray & a, int & i0, int & i1 );
81  int getIntArray( aString & answer, IntegerArray & a, int & i0, int & i1, int & i2 );
82  int getIntArray( aString & answer, IntegerArray & a, int & i0, int & i1, int & i2, int & i3 );
83 
84  // add float and double ****************************************************
85  int getRealArray( aString & answer, RealArray & a );
86  int getRealArray( aString & answer, RealArray & a, int & i0 );
87  int getRealArray( aString & answer, RealArray & a, int & i0, int & i1 );
88  int getRealArray( aString & answer, RealArray & a, int & i0, int & i1, int & i2 );
89  int getRealArray( aString & answer, RealArray & a, int & i0, int & i1, int & i2, int & i3 );
90 
91  int arrayEqualsName( aString & answer, const aString nameList[], IntegerArray & a );
92  int arrayEqualsName( aString & answer, const aString nameList[], IntegerArray & a, int & i0 );
93  int arrayEqualsName( aString & answer, const aString nameList[], IntegerArray & a, int & i0, int & i1);
94  int arrayEqualsName( aString & answer, const aString nameList[], IntegerArray & a, int & i0, int & i1, int & i2);
95  int arrayEqualsName( aString & answer, const aString nameList[], IntegerArray & a,
96  int & i0, int & i1, int & i2, int & i3 );
97 
98  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], IntegerArray & a );
99  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], IntegerArray & a, int & i0 );
100  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], IntegerArray & a, int & i0, int & i1);
101  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], IntegerArray & a, int & i0, int & i1, int & i2);
102  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], IntegerArray & a,
103  int & i0, int & i1, int & i2, int & i3 );
104 
105  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], RealArray & a );
106  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], RealArray & a, int & i0 );
107  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], RealArray & a, int & i0, int & i1);
108  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], RealArray & a, int & i0, int & i1, int & i2);
109  int arrayOfNameEqualsValue( aString & answer, const aString nameList[], RealArray & a,
110  int & i0, int & i1, int & i2, int & i3 );
111 
112  int intArrayValue( aString & answer, int & value, int & i0 );
113  int intArrayValue( aString & answer, int & value, int & i0, int & i1 );
114  int intArrayValue( aString & answer, int & value, int & i0, int & i1, int & i2 );
115  int intArrayValue( aString & answer, int & value, int & i0, int & i1, int & i2, int & i3 );
116 
117  int realArrayValue( aString & answer, real & value, int & i0 );
118  int realArrayValue( aString & answer, real & value, int & i0, int & i1 );
119  int realArrayValue( aString & answer, real & value, int & i0, int & i1, int & i2 );
120  int realArrayValue( aString & answer, real & value, int & i0, int & i1, int & i2, int & i3 );
121 
122  aString getString(aString & answer);
123 
124  private:
125 
126  aString & subString( aString & s, const int i1, const int i2 );
127  int intArrayValue( aString & answer, int & value, const int & numberExpected, int & i0, int & i1, int & i2, int & i3 );
128  int realArrayValue( aString & answer, real & value, const int & numberExpected, int & i0, int & i1, int & i2, int & i3 );
129 
130 };
131 
132 
133 #endif // "NameList.h"