ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/types/Component.cpp
Revision: 1930
Committed: Wed Jan 12 22:41:40 2005 UTC (19 years, 5 months ago) by gezelter
File size: 4198 byte(s)
Log Message:
merging new_design branch into OOPSE-2.0

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 */
41
42 #include <iostream>
43 #include <stdlib.h>
44 #include <string.h>
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;
55 }
56
57 Component::~Component(){
58
59 if( start_array != NULL ) free( start_array );
60 }
61
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;
79 }
80
81 int Component::assignInt( char* lhs, int rhs, char** err ){
82
83 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;
107 }
108
109 int Component::assignDouble( char* lhs, double rhs, char** err ){
110
111 char myErr[1000];
112
113 if( !strcmp( lhs, "molFraction" ) ){
114 if( rhs > 1 || rhs < 0 ){
115 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;
118 }
119 molFraction = rhs;
120 have_molFraction = 1;
121 }
122
123 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;
135 }
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;
142 }
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 }