ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/oopse-1.0/libBASS/Component.cpp
Revision: 1447
Committed: Fri Jul 30 21:01:35 2004 UTC (19 years, 11 months ago) by gezelter
File size: 2115 byte(s)
Log Message:
Initial import of OOPSE sources into cvs tree

File Contents

# Content
1 #include <iostream>
2 #include <stdlib.h>
3 #include <string.h>
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 int Component::assignString( char* lhs, char* rhs, char** err ){
22
23 char myErr[1000];
24
25
26 if( !strcmp( lhs, "type" ) ){
27 strcpy( type, rhs );
28 have_type = 1;
29 }
30
31 else{
32 sprintf(myErr, "Invalid assignment type for Component: %s = %s\n", lhs, rhs);
33 *err = strdup(myErr);
34 return 0;
35 }
36
37 return 1;
38 }
39
40 int Component::assignInt( char* lhs, int rhs, char** err ){
41
42 char myErr[1000];
43
44 if( !strcmp( lhs, "nMol" ) ){
45 nMol = rhs;
46 have_nMol = 1;
47 }
48
49 else if( !strcmp( lhs, "molFraction" ) ){
50 if( rhs > 1 || rhs < 0 ){
51 sprintf(myErr,"Component error. %d is an invalid molFraction. It must lie between 0 and 1\n",rhs);
52 *err = strdup(myErr);
53 return 0;
54 }
55 molFraction = rhs;
56 have_molFraction = 1;
57 }
58
59 else{
60 sprintf(myErr, "Invalid assignment type for Component: %s = %d\n", lhs, rhs);
61 *err = strdup(myErr);
62 return 0;
63 }
64
65 return 1;
66 }
67
68 int Component::assignDouble( char* lhs, double rhs, char** err ){
69
70 char myErr[1000];
71
72 if( !strcmp( lhs, "molFraction" ) ){
73 if( rhs > 1 || rhs < 0 ){
74 sprintf(myErr,"Component error. %lf is an invalid molFraction. It must lie between 0 and 1\n",rhs);
75 *err = strdup(myErr);
76 return 0;
77 }
78 molFraction = rhs;
79 have_molFraction = 1;
80 }
81
82 else if( !strcmp( lhs, "nMol" ) ){
83 nMol = (int) rhs;
84 have_nMol = 1;
85 }
86
87 else{
88 sprintf(myErr, "Invalid assignment type for Component: %s = %lf\n", lhs, rhs);
89 *err = strdup(myErr);
90 return 0;
91 }
92
93 return 1;
94 }
95
96 void Component::startIndex( int* the_start_array, int n_elements ){
97
98 start_array = the_start_array;
99 n_start = n_elements;
100 have_start_array = 1;
101 }
102
103 char* Component::checkMe( void ){
104
105 if( !have_type ){
106 return strdup( "type was not identified for the Component." );
107 }
108
109 return NULL;
110 }