Index: trunk/SophyaLib/SUtils/datacards.cc
===================================================================
--- trunk/SophyaLib/SUtils/datacards.cc	(revision 754)
+++ trunk/SophyaLib/SUtils/datacards.cc	(revision 895)
@@ -1,3 +1,3 @@
-// $Id: datacards.cc,v 1.1 2000-03-02 16:10:58 ansari Exp $
+// $Id: datacards.cc,v 1.2 2000-04-12 17:49:42 ansari Exp $
 //
 // Datacards, acquisition EROS II
@@ -18,5 +18,5 @@
 //++
 // Class	DataCards
-// Lib		Outils++ 
+// Lib		SysTools
 // include	datacards.h
 //
@@ -24,4 +24,5 @@
 //   	de mot-cle (lecture d'un fichier par exemple)
 //--
+
 
 //++
@@ -35,8 +36,20 @@
 //--
 
+/*! 
+    \class SOPHYA::DataCards
+    This class can be used for decoding program parameters from an ascii
+    file. Each line of the ascii contains a keyword starting with \b @ .
+    Lines with any other character in the first column are treated as comments.
+    Keywords can be followed by 0 or more parameters.
+    Processing functions (\b ProcCard) can automatically be called for
+    keywords matching a given pattern. (see \b AddProcF )
+*/ 
+
+/* Default constructor */
 DataCards::DataCards()
 {
 }
 
+/*! constructor with the specification of a parameter file */
 DataCards::DataCards(string const& fn)
 {
@@ -63,4 +76,9 @@
 //--
 
+/*! 
+    Adds a new processing function for all keywords matching the 
+    specified pattern.
+    \param mtch : The pattern - can contain * 
+*/
 void
 DataCards::AddProcF(ProcCard f, string const& mtch)
@@ -85,10 +103,11 @@
 }
 
-void
-DataCards::Clear()
+/*! Resets the objects - Suppresses all cards  */
+void DataCards::Clear()
 {
 cards.erase(cards.begin(), cards.end());
 }
 
+/*! Reads the file named \b fn. if fn=="" the value of \b SOPHYA_DATACARDS is used */
 void
 DataCards::ReadFile(string const& fn)
@@ -96,5 +115,5 @@
   string file = fn;
   if (file == "") {
-    char * efn = getenv("PEIDA_DATACARDS");
+    char * efn = getenv("SOPHYA_DATACARDS");
     if (efn != NULL)    file = efn;  
   }
@@ -104,7 +123,7 @@
     DoReadFile(file);
   } catch(...) {
-    char* wdp = getenv("PEIDA_WORK");
+    char* wdp = getenv("SOPHYA_WORK");
     if (wdp) {
-      cerr << "DataCards::ReadFile() Error reading file " << fn << " (Trying with PEIDA_WORK) \n";
+      cerr << "DataCards::ReadFile() Error reading file " << fn << " (Trying with SOPHYA_WORK) \n";
       file = wdp + file;
       DoReadFile(file);
@@ -115,4 +134,5 @@
 }
 
+/*! Appends a card, represented by the string \b crd to the list of cards */
 void
 DataCards::AppendCard(string const& crd)
@@ -145,82 +165,4 @@
 }
 
-void
-DataCards::DoReadFile(string const& fn)
-{
-char line_buff[512];
-FILE *fip;
-
-if ( (fip = fopen(fn.c_str(),"r")) == NULL )  
-  throw IOExc("DataCards::DoReadFile() fopen Error ") ;
-while (fgets(line_buff,511,fip) != NULL)
-  {
-  line_buff[strlen(line_buff)-1] = '\0';   /*  LF/CR de la fin */
-  string line(line_buff);
-  AppendCard(line);
-  }
-}
-
-int
-DataCards::ApplyPF(CrdPF & cpf, string const& key, string const& toks)
-{
-int l,lk;
-int rc = 0;
-// On verifie si le "pattern" correspond
-bool mtch = false;
-l = cpf.patt.length(); 
-if (cpf.patt == "*")  mtch = true;
-else if (cpf.patt[0] == '*')   
-  {
-  lk = key.length();
-  if (cpf.patt[l-1] != '*')
-    {
-    if (strcmp(key.c_str()+(lk-l+1), cpf.patt.c_str()+1) == 0)   mtch = true;
-    }
-  else if  (key.find(cpf.patt.substr(1,l-2)) < lk)  mtch = true;
-  }
-else if (cpf.patt[l-1] == '*')
-  {
-  if ( strncmp(key.c_str(), cpf.patt.c_str(),l-1) == 0)  mtch = true;
-  }
-else if (key == cpf.patt)  mtch = true;
-
-// Si oui, on appelle la fonction correspondante
-if (mtch)  rc = cpf.pf(key, toks); 
-
-return(rc);
-}
-
-
-int
-DataCards::ApplyPFL(string const& key, string const& toks)
-{
-int rc = 0;
-CrdPFList::iterator icf;
-for(icf = cpfs.begin(); icf != cpfs.end(); icf++)
-  rc += ApplyPF((*icf), key, toks);
-return(rc);
-}
-
-void  
-DataCards::RemoveCard(string const& key)
-{
-CardList::iterator i;
-for(i=cards.begin(); i != cards.end(); i++)
-  if ((*i).kw == key) { cards.erase(i);  break;  }
-}
-
-DataCards::Card *
-DataCards::FindKey(string const& key)
-{
-/*
-  CardList::iterator i = find_if(cards.begin(), cards.end(), bind2nd(KeyEq(),key));
-  if (i == cards.end() ) return NULL;
-*/
-  CardList::iterator i;
-  for(i=cards.begin(); i != cards.end(); i++)
-    if ((*i).kw == key) return &*i;
-
-  return NULL;
-}
 
 //++
@@ -246,4 +188,5 @@
 
 
+/*! Returns true if \b key is present in the list */
 bool
 DataCards::HasKey(string const& key)
@@ -252,4 +195,5 @@
 }
 
+//! Returns the total number of cards 
 int 
 DataCards::NbCards()
@@ -258,4 +202,5 @@
 }
 
+/*! Returns the number of parameters for card \b key. (-1) if \b key not present  */
 int 
 DataCards::NbParam(string const& key)
@@ -266,4 +211,5 @@
 }
 
+/*! Returns the parameter number \b numero for card \b key */
 string
 DataCards::SParam(string const& key, int numero, string def)
@@ -275,4 +221,5 @@
 }
 
+/*! Returns the parameter number \b numero for card \b key, converted to type long */
 long
 DataCards::IParam(string const& key, int numero, long def)
@@ -286,4 +233,5 @@
 }
 
+/*! Returns the parameter number \b numero for card \b key, converted to type double */
 double
 DataCards::DParam(string const& key, int numero, double def)
@@ -298,15 +246,96 @@
 
    
-ostream& operator << (ostream& s, DataCards c)
-{
-  for (DataCards::CardList::iterator i = c.cards.begin(); i != c.cards.end(); i++) {
+/*! Prints the list of cards on the output stream \b s */
+void
+DataCards::Print(ostream& s) const
+{
+  for (CardList::const_iterator i = cards.begin(); i != cards.end(); i++) {
     s << setw(10) << (*i).kw << " ";
-    for (vector<string>::iterator j = (*i).tokens.begin(); j != (*i).tokens.end(); j++)
+    for (vector<string>::const_iterator j = (*i).tokens.begin(); j != (*i).tokens.end(); j++)
       s << (*j) << " ";
     s << endl;
   }
-  return s;
-}
-
-
-
+}
+
+/*! Reads the file named \b fn. */
+void
+DataCards::DoReadFile(string const& fn)
+{
+char line_buff[512];
+FILE *fip;
+
+if ( (fip = fopen(fn.c_str(),"r")) == NULL )  
+  throw IOExc("DataCards::DoReadFile() fopen Error ") ;
+while (fgets(line_buff,511,fip) != NULL)
+  {
+  line_buff[strlen(line_buff)-1] = '\0';   /*  LF/CR de la fin */
+  string line(line_buff);
+  AppendCard(line);
+  }
+}
+
+int
+DataCards::ApplyPF(CrdPF & cpf, string const& key, string const& toks)
+{
+int l,lk;
+int rc = 0;
+// On verifie si le "pattern" correspond
+bool mtch = false;
+l = cpf.patt.length(); 
+if (cpf.patt == "*")  mtch = true;
+else if (cpf.patt[0] == '*')   
+  {
+  lk = key.length();
+  if (cpf.patt[l-1] != '*')
+    {
+    if (strcmp(key.c_str()+(lk-l+1), cpf.patt.c_str()+1) == 0)   mtch = true;
+    }
+  else if  (key.find(cpf.patt.substr(1,l-2)) < lk)  mtch = true;
+  }
+else if (cpf.patt[l-1] == '*')
+  {
+  if ( strncmp(key.c_str(), cpf.patt.c_str(),l-1) == 0)  mtch = true;
+  }
+else if (key == cpf.patt)  mtch = true;
+
+// Si oui, on appelle la fonction correspondante
+if (mtch)  rc = cpf.pf(key, toks); 
+
+return(rc);
+}
+
+
+int
+DataCards::ApplyPFL(string const& key, string const& toks)
+{
+int rc = 0;
+CrdPFList::iterator icf;
+for(icf = cpfs.begin(); icf != cpfs.end(); icf++)
+  rc += ApplyPF((*icf), key, toks);
+return(rc);
+}
+
+void  
+DataCards::RemoveCard(string const& key)
+{
+CardList::iterator i;
+for(i=cards.begin(); i != cards.end(); i++)
+  if ((*i).kw == key) { cards.erase(i);  break;  }
+}
+
+DataCards::Card *
+DataCards::FindKey(string const& key)
+{
+/*
+  CardList::iterator i = find_if(cards.begin(), cards.end(), bind2nd(KeyEq(),key));
+  if (i == cards.end() ) return NULL;
+*/
+  CardList::iterator i;
+  for(i=cards.begin(); i != cards.end(); i++)
+    if ((*i).kw == key) return &*i;
+
+  return NULL;
+}
+
+
+
