1 |
#include <iostream> |
2 |
#include <cstdlib> |
3 |
#include <cstring> |
4 |
|
5 |
#include "Component.hpp" |
6 |
|
7 |
Component::Component(){ |
8 |
|
9 |
start_array = NULL; |
10 |
have_type = 0; |
11 |
have_nMol = 0; |
12 |
have_molFraction = 0; |
13 |
have_start_array = 0; |
14 |
} |
15 |
|
16 |
Component::~Component(){ |
17 |
|
18 |
if( start_array != NULL ) free( start_array ); |
19 |
} |
20 |
|
21 |
void Component::assignString( char* lhs, char* rhs ){ |
22 |
|
23 |
if( !strcmp( lhs, "type" ) ){ |
24 |
strcpy( type, rhs ); |
25 |
have_type = 1; |
26 |
} |
27 |
|
28 |
else{ |
29 |
std::cerr << "Invalid assignment type for Component: " |
30 |
<< lhs << " = " << rhs << "\n"; |
31 |
exit(1); |
32 |
} |
33 |
} |
34 |
|
35 |
void Component::assignInt( char* lhs, int rhs ){ |
36 |
|
37 |
if( !strcmp( lhs, "nMol" ) ){ |
38 |
nMol = rhs; |
39 |
have_nMol = 1; |
40 |
} |
41 |
|
42 |
else if( !strcmp( lhs, "molFraction" ) ){ |
43 |
if( rhs > 1 || rhs < 0 ){ |
44 |
std::cerr << "Component error. " << rhs |
45 |
<< " is an invalid molFraction. It must lie between 0 and 1\n"; |
46 |
exit(1); |
47 |
} |
48 |
molFraction = rhs; |
49 |
have_molFraction = 1; |
50 |
} |
51 |
|
52 |
else{ |
53 |
std::cerr << "Invalid assignment type for Component: " |
54 |
<< lhs << " = " << rhs << "\n"; |
55 |
exit(1); |
56 |
} |
57 |
} |
58 |
|
59 |
void Component::assignDouble( char* lhs, double rhs ){ |
60 |
|
61 |
if( !strcmp( lhs, "molFraction" ) ){ |
62 |
if( rhs > 1 || rhs < 0 ){ |
63 |
std::cerr << "Component error. " << rhs |
64 |
<< " is an invalid molFraction. It must lie between 0 and 1\n"; |
65 |
exit(1); |
66 |
} |
67 |
molFraction = rhs; |
68 |
have_molFraction = 1; |
69 |
} |
70 |
|
71 |
else if( !strcmp( lhs, "nMol" ) ){ |
72 |
nMol = (int) rhs; |
73 |
have_nMol = 1; |
74 |
} |
75 |
|
76 |
else{ |
77 |
std::cerr << "Invalid assignment type for Component: " |
78 |
<< lhs << " = " << rhs << "\n"; |
79 |
exit(1); |
80 |
} |
81 |
} |
82 |
|
83 |
void Component::startIndex( int* the_start_array, int n_elements ){ |
84 |
|
85 |
start_array = the_start_array; |
86 |
n_start = n_elements; |
87 |
have_start_array = 1; |
88 |
} |
89 |
|
90 |
char* Component::checkMe( void ){ |
91 |
|
92 |
if( !have_type ){ |
93 |
return strdup( "type was not identified for the Component." ); |
94 |
} |
95 |
|
96 |
return NULL; |
97 |
} |