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 <stdlib.h> |
43 |
#include <stdio.h> |
44 |
#include <string.h> |
45 |
#include <iostream> |
46 |
|
47 |
#include "types/RigidBodyStamp.hpp" |
48 |
|
49 |
char RigidBodyStamp::errMsg[500]; |
50 |
|
51 |
RigidBodyStamp::RigidBodyStamp(){ |
52 |
|
53 |
unhandled = NULL; |
54 |
have_members = 0; |
55 |
have_extras = 0; |
56 |
n_members = 0; |
57 |
which = 0; |
58 |
|
59 |
} |
60 |
|
61 |
RigidBodyStamp::~RigidBodyStamp(){ |
62 |
int i; |
63 |
|
64 |
if( unhandled != NULL ) delete unhandled; |
65 |
|
66 |
free(members); |
67 |
|
68 |
} |
69 |
|
70 |
char* RigidBodyStamp::assignString( char* lhs, char* rhs ){ |
71 |
|
72 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
73 |
else unhandled->add( lhs, rhs ); |
74 |
have_extras = 1; |
75 |
return NULL; |
76 |
|
77 |
} |
78 |
|
79 |
char* RigidBodyStamp::assignDouble( char* lhs, double rhs ){ |
80 |
int i; |
81 |
|
82 |
if( !strcmp( lhs, "nMembers" ) ){ |
83 |
n_members = (int)rhs; |
84 |
|
85 |
if( have_members ){ |
86 |
sprintf( errMsg, |
87 |
"RigidBodyStamp error, nMembers already declared" |
88 |
" for this RigidBody.\n"); |
89 |
return strdup( errMsg ); |
90 |
} |
91 |
have_members = 1; |
92 |
members = (int *) calloc(n_members, sizeof(int)); |
93 |
} |
94 |
else { |
95 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
96 |
else unhandled->add( lhs, rhs ); |
97 |
have_extras = 1; |
98 |
} |
99 |
return NULL; |
100 |
} |
101 |
|
102 |
char* RigidBodyStamp::assignInt( char* lhs, int rhs ){ |
103 |
int i; |
104 |
|
105 |
if( !strcmp( lhs, "nMembers" ) ){ |
106 |
n_members = rhs; |
107 |
|
108 |
if( have_members ){ |
109 |
sprintf( errMsg, |
110 |
"RigidBodyStamp error, nMembers already declared for" |
111 |
" this RigidBody.\n"); |
112 |
return strdup( errMsg ); |
113 |
} |
114 |
have_members = 1; |
115 |
members = (int *) calloc(n_members, sizeof(int)); |
116 |
} |
117 |
else { |
118 |
if( unhandled == NULL ) unhandled = new LinkedAssign( lhs, rhs ); |
119 |
else unhandled->add( lhs, rhs ); |
120 |
have_extras = 1; |
121 |
} |
122 |
return NULL; |
123 |
} |
124 |
|
125 |
char* RigidBodyStamp::addMember( int atomIndex ){ |
126 |
|
127 |
if( have_members && which < n_members ) { |
128 |
members[which] = atomIndex; |
129 |
which++; |
130 |
} else { |
131 |
if( have_members ){ |
132 |
sprintf( errMsg, "RigidBodyStamp error, %d out of nMembers range", |
133 |
which ); |
134 |
return strdup( errMsg ); |
135 |
} |
136 |
else return strdup("RigidBodyStamp error, nMembers not given before" |
137 |
" member list declaration." ); |
138 |
} |
139 |
return NULL; |
140 |
} |
141 |
|
142 |
char* RigidBodyStamp::checkMe( void ){ |
143 |
|
144 |
int i; |
145 |
short int no_member; |
146 |
|
147 |
if( !have_members ){ |
148 |
return strdup( "RigidBodyStamp error. RigidBody contains no members." ); |
149 |
} |
150 |
|
151 |
if (which < n_members) { |
152 |
sprintf( errMsg, |
153 |
"RigidBodyStamp error. Not all of the members were" |
154 |
" declared for this RigidBody."); |
155 |
return strdup( errMsg ); |
156 |
} |
157 |
|
158 |
return NULL; |
159 |
|
160 |
} |