ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/types/Component.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/types/Component.cpp (file contents):
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2469 by tim, Fri Dec 2 15:38:03 2005 UTC

# Line 45 | Line 45 | Component::Component(){
45  
46   #include "types/Component.hpp"
47  
48 < Component::Component(){
49 <  
50 <  start_array = NULL;
51 <  have_type = 0;
52 <  have_nMol = 0;
53 <  have_molFraction = 0;
54 <  have_start_array = 0;
48 > namespace oopse {
49 > Component::Component() : moleculeStamp_(NULL) {
50 >    DefineParameter(Type, "type");
51 >    DefineParameter(NMol, "nMol");
52   }
53  
54 < Component::~Component(){
58 <  
59 <  if( start_array != NULL ) free( start_array );
60 < }
54 > Component::~Component() {
55  
62 int Component::assignString( char* lhs, char* rhs, char** err ){
63  
64  char myErr[1000];
65
66
67  if( !strcmp( lhs, "type" ) ){
68    strcpy( type, rhs );
69    have_type = 1;
70  }
71
72  else{
73    sprintf(myErr, "Invalid assignment type for Component: %s = %s\n", lhs, rhs);
74    *err = strdup(myErr);
75    return 0;
76  }
77
78  return 1;
56   }
57  
58 < int Component::assignInt( char* lhs, int rhs, char** err ){
59 <  
60 <  char myErr[1000];
84 <
85 <  if( !strcmp( lhs, "nMol" ) ){
86 <    nMol = rhs;
87 <    have_nMol = 1;
88 <  }
89 <
90 <  else if( !strcmp( lhs, "molFraction" ) ){
91 <    if( rhs > 1 || rhs < 0 ){
92 <      sprintf(myErr,"Component error. %d is an invalid molFraction. It must lie between 0 and 1\n",rhs);
93 <      *err = strdup(myErr);
94 <      return 0;
95 <    }
96 <    molFraction = rhs;
97 <    have_molFraction = 1;
98 <  }
99 <
100 <  else{
101 <    sprintf(myErr, "Invalid assignment type for Component: %s = %d\n", lhs, rhs);
102 <    *err = strdup(myErr);
103 <    return 0;
104 <  }
105 <
106 <  return 1;
58 > void Component::validate() {
59 >    CheckParameter(Type, isNotEmpty());
60 >    CheckParameter(NMol, isPositive());
61   }
62  
63 < int Component::assignDouble( char* lhs, double rhs, char** err ){
64 <
65 <  char myErr[1000];
66 <
67 <  if( !strcmp( lhs, "molFraction" ) ){
68 <    if( rhs > 1 || rhs < 0 ){
69 <      sprintf(myErr,"Component error. %lf is an invalid molFraction. It must lie between 0 and 1\n",rhs);
116 <      *err = strdup(myErr);
117 <      return 0;
63 > bool Component::findMoleculeStamp(const std::map<std::string, MoleculeStamp*>& molStamps) {
64 >    bool ret = false;
65 >    std::map<std::string, MoleculeStamp*>::const_iterator i;
66 >    i = molStamps.find(getType());
67 >    if (i != molStamps.end()) {
68 >        moleculeStamp_ = i->second;
69 >        ret = true;
70      }
119    molFraction = rhs;
120    have_molFraction = 1;
121  }
71  
72 <  else if( !strcmp( lhs, "nMol" ) ){
124 <    nMol = (int) rhs;
125 <    have_nMol = 1;
126 <  }
127 <  
128 <  else{
129 <    sprintf(myErr, "Invalid assignment type for Component: %s = %lf\n", lhs, rhs);
130 <    *err = strdup(myErr);
131 <    return 0;
132 <  }
133 <
134 <  return 1;
72 >    return ret;
73   }
136
137 void Component::startIndex( int* the_start_array, int n_elements ){
138  
139  start_array = the_start_array;
140  n_start = n_elements;
141  have_start_array = 1;
74   }
143
144 char* Component::checkMe( void ){
145  
146  if( !have_type ){
147    return strdup( "type was not identified for the Component." );
148  }
149
150  return NULL;
151 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines