NAMD
Classes | Public Member Functions | Static Public Member Functions | List of all members
MGridforceParamsList Class Reference

#include <MGridforceParams.h>

Public Member Functions

 MGridforceParamsList ()
 
 ~MGridforceParamsList ()
 
void clear ()
 
MGridforceParamsfind_key (const char *key)
 
int index_for_key (const char *key)
 
MGridforceParamsat_index (int idx)
 
MGridforceParamsadd (const char *key)
 
MGridforceParamsget_first ()
 
void pack_data (MOStream *msg)
 
void unpack_data (MIStream *msg)
 

Static Public Member Functions

static int atoBool (const char *s)
 

Detailed Description

Definition at line 50 of file MGridforceParams.h.

Constructor & Destructor Documentation

MGridforceParamsList::MGridforceParamsList ( )
inline

Definition at line 52 of file MGridforceParams.h.

References clear().

52  {
53  clear();
54  }
MGridforceParamsList::~MGridforceParamsList ( )
inline

Definition at line 56 of file MGridforceParams.h.

References clear().

57  {
58  MGFElem* cur;
59  while (head != NULL) {
60  cur = head;
61  head = cur->nxt;
62  delete cur;
63  }
64  clear();
65  }

Member Function Documentation

MGridforceParams * MGridforceParamsList::add ( const char *  key)

Definition at line 75 of file MGridforceParams.C.

References find_key(), MGridforceParams::gridforceCol, MGridforceParams::gridforceFile, MGridforceParams::gridforceKey, MGridforceParams::gridforceQcol, MGridforceParams::gridforceVfile, and MGridforceParams::next.

Referenced by unpack_data().

76 {
77  // If the key is already in the list, we can't add it
78  if (find_key(key)!=NULL) {
79  return NULL;
80  }
81 
82  MGFElem* new_elem = new MGFElem();
83  int len = strlen(key);
84  MGridforceParams* elem = &(new_elem->elem);
85  elem->gridforceKey = new char[len+1];
86  strncpy(elem->gridforceKey,key,len+1);
87  elem->gridforceVfile = NULL;
88  elem->gridforceFile = NULL;
89  elem->gridforceCol = NULL;
90  elem->gridforceQcol = NULL;
91  elem->next = NULL;
92  new_elem->nxt = NULL;
93  if (head == NULL) {
94  head = new_elem;
95  }
96  if (tail != NULL) {
97  tail->nxt = new_elem;
98  tail->elem.next = elem;
99  }
100  tail = new_elem;
101  n_elements++;
102 
103  return elem;
104 }
MGridforceParams * find_key(const char *key)
MGridforceParams * next
MGridforceParams * MGridforceParamsList::at_index ( int  idx)

Definition at line 53 of file MGridforceParams.C.

Referenced by Node::updateGridScale().

54 {
55  MGFElem* cur = head;
56  MGFElem* found = NULL;
57  MGridforceParams* result = NULL;
58 
59  int counter = 0;
60  while (found == NULL && cur != NULL) {
61  if (counter == idx) {
62  found = cur;
63  } else {
64  cur = cur->nxt;
65  counter++;
66  }
67  }
68  if (found != NULL) {
69  result = &(found->elem);
70  }
71  return result;
72 }
static int MGridforceParamsList::atoBool ( const char *  s)
inlinestatic

Definition at line 90 of file MGridforceParams.h.

91  {
92  if (!strcasecmp(s, "on")) return 1;
93  if (!strcasecmp(s, "off")) return 0;
94  if (!strcasecmp(s, "true")) return 1;
95  if (!strcasecmp(s, "false")) return 0;
96  if (!strcasecmp(s, "yes")) return 1;
97  if (!strcasecmp(s, "no")) return 0;
98  if (!strcasecmp(s, "1")) return 1;
99  if (!strcasecmp(s, "0")) return 0;
100  return -1;
101  }
void MGridforceParamsList::clear ( )
inline

Definition at line 70 of file MGridforceParams.h.

Referenced by MGridforceParamsList(), and ~MGridforceParamsList().

70  {
71  head = tail = NULL;
72  n_elements = 0;
73  }
MGridforceParams * MGridforceParamsList::find_key ( const char *  key)

Definition at line 13 of file MGridforceParams.C.

Referenced by add(), Node::reloadGridforceGrid(), and Node::updateGridScale().

14 {
15  MGFElem* cur = head;
16  MGFElem* found = NULL;
17  MGridforceParams* result = NULL;
18 
19  while (found == NULL && cur != NULL) {
20  if (!strcasecmp((cur->elem).gridforceKey,key)) {
21  found = cur;
22  } else {
23  cur = cur->nxt;
24  }
25  }
26  if (found != NULL) {
27  result = &(found->elem);
28  }
29  return result;
30 }
MGridforceParams* MGridforceParamsList::get_first ( )
inline

Definition at line 80 of file MGridforceParams.h.

Referenced by Molecule::build_gridforce_params(), and pack_data().

80  {
81  if (head == NULL) {
82  return NULL;
83  } else return &(head->elem);
84  }
int MGridforceParamsList::index_for_key ( const char *  key)

Definition at line 32 of file MGridforceParams.C.

Referenced by colvarproxy_namd::init_volmap(), Node::reloadGridforceGrid(), and Node::updateGridScale().

33 {
34  MGFElem* cur = head;
35  MGFElem* found = NULL;
36  int result = -1;
37 
38  int idx = 0;
39  while (found == NULL && cur != NULL) {
40  if (!strcasecmp((cur->elem).gridforceKey,key)) {
41  found = cur;
42  } else {
43  cur = cur->nxt;
44  idx++;
45  }
46  }
47  if (found != NULL) {
48  result = idx;
49  }
50  return result;
51 }
void MGridforceParamsList::pack_data ( MOStream msg)

Definition at line 106 of file MGridforceParams.C.

References get_first(), MGridforceParams::gridforceCheckSize, MGridforceParams::gridforceCol, MGridforceParams::gridforceCont, MGridforceParams::gridforceFile, MGridforceParams::gridforceKey, MGridforceParams::gridforceLite, MGridforceParams::gridforceQcol, MGridforceParams::gridforceScale, MGridforceParams::gridforceVfile, MGridforceParams::gridforceVOffset, MGridforceParams::gridforceVolts, NAMD_die(), MGridforceParams::next, and MOStream::put().

107 {
108  int i = n_elements;
109  msg->put(n_elements);
110  MGridforceParams *elem = get_first();
111  while (elem != NULL) {
112  int len;
113  len = strlen(elem->gridforceKey) + 1;
114  msg->put(len);
115  msg->put(len,elem->gridforceKey);
116 
117  len = strlen(elem->gridforceVfile) + 1;
118  msg->put(len);
119  msg->put(len,elem->gridforceVfile);
120 
121  Vector v = elem->gridforceScale;
122  msg->put(&v);
123 
124  len = strlen(elem->gridforceFile) + 1;
125  msg->put(len);
126  msg->put(len,elem->gridforceFile);
127 
128  len = strlen(elem->gridforceCol) + 1;
129  msg->put(len);
130  msg->put(len,elem->gridforceCol);
131 
132  if (elem->gridforceQcol == NULL)
133  msg->put(1); // Qcol_is_null = true
134  else {
135  msg->put(0); // Qcol_is_null = false
136  len = strlen(elem->gridforceQcol) + 1;
137  msg->put(len);
138  msg->put(len,elem->gridforceQcol);
139  }
140 
141  v = elem->gridforceVOffset;
142  msg->put(&v);
143 
144  short boolvals[6];
145  boolvals[0] = (elem->gridforceCont[0] ? 1 : 0);
146  boolvals[1] = (elem->gridforceCont[1] ? 1 : 0);
147  boolvals[2] = (elem->gridforceCont[2] ? 1 : 0);
148  boolvals[3] = (elem->gridforceVolts ? 1 : 0);
149  boolvals[4] = (elem->gridforceLite ? 1 : 0);
150  boolvals[5] = (elem->gridforceCheckSize ? 1 : 0);
151  msg->put(6,boolvals);
152 
153  i--;
154  elem = elem->next;
155  }
156  if (i != 0) {
157  NAMD_die("MGridforceParams message packing error\n");
158  }
159  return;
160 }
Definition: Vector.h:64
MGridforceParams * get_first()
void NAMD_die(const char *err_msg)
Definition: common.C:83
MGridforceParams * next
MOStream * put(char data)
Definition: MStream.h:112
void MGridforceParamsList::unpack_data ( MIStream msg)

Definition at line 162 of file MGridforceParams.C.

References add(), MIStream::get(), MGridforceParams::gridforceCheckSize, MGridforceParams::gridforceCol, MGridforceParams::gridforceCont, MGridforceParams::gridforceFile, MGridforceParams::gridforceLite, MGridforceParams::gridforceQcol, MGridforceParams::gridforceScale, MGridforceParams::gridforceVfile, MGridforceParams::gridforceVOffset, and MGridforceParams::gridforceVolts.

163 {
164  int elements;
165  msg->get(elements);
166 
167  for(int i=0; i < elements; i++) {
168  // Get key
169  int len;
170  msg->get(len);
171  char *key = new char[len];
172  msg->get(len,key);
173  MGridforceParams *elem = add(key);
174 
175  msg->get(len);
176  char *str = new char[len];
177  msg->get(len,str);
178  elem->gridforceVfile = str;
179 
180  Vector v;
181  msg->get(&v);
182  elem->gridforceScale = v;
183 
184  msg->get(len);
185  str = new char[len];
186  msg->get(len,str);
187  elem->gridforceFile = str;
188 
189  msg->get(len);
190  str = new char[len];
191  msg->get(len,str);
192  elem->gridforceCol = str;
193 
194  int qcol_is_null;
195  msg->get(qcol_is_null);
196  if (qcol_is_null)
197  elem->gridforceQcol = NULL;
198  else {
199  msg->get(len);
200  str = new char[len];
201  msg->get(len,str);
202  elem->gridforceQcol = str;
203  }
204 
205  msg->get(&v);
206  elem->gridforceVOffset = v;
207 
208  short boolvals[6];
209  msg->get(6,boolvals);
210  elem->gridforceCont[0] = ( boolvals[0] != 0 );
211  elem->gridforceCont[1] = ( boolvals[1] != 0 );
212  elem->gridforceCont[2] = ( boolvals[2] != 0 );
213  elem->gridforceVolts = ( boolvals[3] != 0 );
214  elem->gridforceLite = ( boolvals[4] != 0 );
215  elem->gridforceCheckSize = ( boolvals[5] != 0 );
216 
217  delete [] key;
218  }
219 }
Definition: Vector.h:64
MIStream * get(char &data)
Definition: MStream.h:29
MGridforceParams * add(const char *key)

The documentation for this class was generated from the following files: