MGridforceParamsList Class Reference

#include <MGridforceParams.h>

List of all members.

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)

Classes

class  MGFElem


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().

00052                          {
00053     clear();
00054   }

MGridforceParamsList::~MGridforceParamsList (  )  [inline]

Definition at line 56 of file MGridforceParams.h.

References clear().

00057   {
00058     MGFElem* cur;
00059     while (head != NULL) {
00060       cur = head;
00061       head = cur->nxt;
00062       delete cur;
00063     }
00064     clear();
00065   }


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().

00076 {
00077     // If the key is already in the list, we can't add it
00078     if (find_key(key)!=NULL) {
00079       return NULL;
00080     }
00081     
00082     MGFElem* new_elem = new MGFElem();
00083     int len = strlen(key);
00084     MGridforceParams* elem = &(new_elem->elem);
00085     elem->gridforceKey = new char[len+1];
00086     strncpy(elem->gridforceKey,key,len+1);
00087     elem->gridforceVfile = NULL;
00088     elem->gridforceFile = NULL;
00089     elem->gridforceCol = NULL;
00090     elem->gridforceQcol = NULL;
00091     elem->next = NULL;
00092     new_elem->nxt = NULL;
00093     if (head == NULL) {
00094       head = new_elem;
00095     }
00096     if (tail != NULL) {
00097       tail->nxt = new_elem;
00098       tail->elem.next = elem;
00099     }
00100     tail = new_elem;
00101     n_elements++;
00102     
00103     return elem;
00104 }

MGridforceParams * MGridforceParamsList::at_index ( int  idx  ) 

Definition at line 53 of file MGridforceParams.C.

Referenced by Node::updateGridScale().

00054 {
00055     MGFElem* cur = head;
00056     MGFElem* found = NULL;
00057     MGridforceParams* result = NULL;
00058     
00059     int counter = 0;
00060     while (found == NULL && cur != NULL) {
00061       if (counter == idx) {
00062         found = cur;
00063       } else {
00064         cur = cur->nxt;
00065         counter++;
00066       }
00067     }
00068     if (found != NULL) {
00069         result = &(found->elem);
00070     }
00071     return result;
00072 }

static int MGridforceParamsList::atoBool ( const char *  s  )  [inline, static]

Definition at line 90 of file MGridforceParams.h.

00091   {
00092     if (!strcasecmp(s, "on")) return 1;
00093     if (!strcasecmp(s, "off")) return 0;
00094     if (!strcasecmp(s, "true")) return 1;
00095     if (!strcasecmp(s, "false")) return 0;
00096     if (!strcasecmp(s, "yes")) return 1;
00097     if (!strcasecmp(s, "no")) return 0;
00098     if (!strcasecmp(s, "1")) return 1;
00099     if (!strcasecmp(s, "0")) return 0;
00100     return -1;
00101   }

void MGridforceParamsList::clear (  )  [inline]

Definition at line 70 of file MGridforceParams.h.

Referenced by MGridforceParamsList(), SimParameters::receive_SimParameters(), and ~MGridforceParamsList().

00070                {
00071     head = tail = NULL;
00072     n_elements = 0;
00073   }

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

Definition at line 13 of file MGridforceParams.C.

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

00014 {
00015     MGFElem* cur = head;
00016     MGFElem* found = NULL;
00017     MGridforceParams* result = NULL;
00018     
00019     while (found == NULL && cur != NULL) {
00020        if (!strcasecmp((cur->elem).gridforceKey,key)) {
00021         found = cur;
00022       } else {
00023         cur = cur->nxt;
00024       }
00025     }
00026     if (found != NULL) {
00027       result = &(found->elem);
00028     }
00029     return result;
00030 }

MGridforceParams* MGridforceParamsList::get_first (  )  [inline]

Definition at line 80 of file MGridforceParams.h.

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

00080                                 {
00081     if (head == NULL) {
00082       return NULL;
00083     } else return &(head->elem);
00084   }

int MGridforceParamsList::index_for_key ( const char *  key  ) 

Definition at line 32 of file MGridforceParams.C.

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

00033 {
00034     MGFElem* cur = head;
00035     MGFElem* found = NULL;
00036     int result = -1;
00037     
00038     int idx = 0;
00039     while (found == NULL && cur != NULL) {
00040        if (!strcasecmp((cur->elem).gridforceKey,key)) {
00041         found = cur;
00042       } else {
00043         cur = cur->nxt;
00044         idx++;
00045       }
00046     }
00047     if (found != NULL) {
00048         result = idx;
00049     }
00050     return result;
00051 }

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().

Referenced by SimParameters::send_SimParameters().

00107 {
00108     int i = n_elements;
00109     msg->put(n_elements);
00110     MGridforceParams *elem = get_first();
00111     while (elem != NULL) {
00112       int len;
00113       len = strlen(elem->gridforceKey) + 1;
00114       msg->put(len);
00115       msg->put(len,elem->gridforceKey);
00116 
00117       len = strlen(elem->gridforceVfile) + 1;
00118       msg->put(len);
00119       msg->put(len,elem->gridforceVfile);
00120 
00121       Vector v = elem->gridforceScale;
00122       msg->put(&v);
00123       
00124       len = strlen(elem->gridforceFile) + 1;
00125       msg->put(len);
00126       msg->put(len,elem->gridforceFile);
00127       
00128       len = strlen(elem->gridforceCol) + 1;
00129       msg->put(len);
00130       msg->put(len,elem->gridforceCol);
00131       
00132       if (elem->gridforceQcol == NULL) 
00133         msg->put(1); // Qcol_is_null = true
00134       else {
00135         msg->put(0); // Qcol_is_null = false
00136         len = strlen(elem->gridforceQcol) + 1;
00137         msg->put(len);
00138         msg->put(len,elem->gridforceQcol);
00139       }
00140       
00141       v = elem->gridforceVOffset;
00142       msg->put(&v);
00143       
00144       short boolvals[6];
00145       boolvals[0] = (elem->gridforceCont[0] ? 1 : 0);
00146       boolvals[1] = (elem->gridforceCont[1] ? 1 : 0);
00147       boolvals[2] = (elem->gridforceCont[2] ? 1 : 0);
00148       boolvals[3] = (elem->gridforceVolts ? 1 : 0);
00149       boolvals[4] = (elem->gridforceLite ? 1 : 0);
00150       boolvals[5] = (elem->gridforceCheckSize ? 1 : 0);
00151       msg->put(6,boolvals);
00152       
00153       i--;
00154       elem = elem->next;
00155     }
00156     if (i != 0) {
00157       NAMD_die("MGridforceParams message packing error\n");
00158     }
00159     return;
00160 }

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.

Referenced by SimParameters::receive_SimParameters().

00163 {
00164     int elements;
00165     msg->get(elements);
00166     
00167     for(int i=0; i < elements; i++) {
00168       // Get key
00169       int len;
00170       msg->get(len);
00171       char *key = new char[len];
00172       msg->get(len,key);
00173       MGridforceParams *elem = add(key);
00174       
00175       msg->get(len);
00176       char *str = new char[len];
00177       msg->get(len,str);
00178       elem->gridforceVfile = str;
00179 
00180       Vector v;
00181       msg->get(&v);
00182       elem->gridforceScale = v;
00183       
00184       msg->get(len);
00185       str = new char[len];
00186       msg->get(len,str);
00187       elem->gridforceFile = str;
00188       
00189       msg->get(len);
00190       str = new char[len];
00191       msg->get(len,str);
00192       elem->gridforceCol = str;
00193       
00194       int qcol_is_null;
00195       msg->get(qcol_is_null);
00196       if (qcol_is_null)
00197         elem->gridforceQcol = NULL;
00198       else {
00199         msg->get(len);
00200         str = new char[len];
00201         msg->get(len,str);
00202         elem->gridforceQcol = str;
00203       }
00204       
00205       msg->get(&v);
00206       elem->gridforceVOffset = v;
00207       
00208       short boolvals[6];
00209       msg->get(6,boolvals);
00210       elem->gridforceCont[0] = ( boolvals[0] != 0 );
00211       elem->gridforceCont[1] = ( boolvals[1] != 0 );
00212       elem->gridforceCont[2] = ( boolvals[2] != 0 );
00213       elem->gridforceVolts = ( boolvals[3] != 0 );
00214       elem->gridforceLite = ( boolvals[4] != 0 );
00215       elem->gridforceCheckSize = ( boolvals[5] != 0 );
00216       
00217       delete [] key;
00218     }
00219 }


The documentation for this class was generated from the following files:
Generated on Mon Sep 25 01:17:18 2017 for NAMD by  doxygen 1.4.7