src/Utility/DiscMeta.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef DISC_META_H
00012 #define DISC_META_H
00013 
00014 // include files
00015 #include "Utility/Pstring.h"
00016 #include "Utility/Inform.h"
00017 #include "Utility/vmap.h"
00018 
00019 #include <stdio.h>
00020 
00021 /***************************************************************************
00022  * DiscMeta - reads in information in a Disc meta file, which is a file in
00023  * the format
00024  *
00025  * # comment line
00026  * keyword [=] value
00027  * keyword [=] value
00028  * ...
00029  *
00030  * An optional = may separate the single-word keyword and the value.  This
00031  * class stores the list of lines, and can be queried about them.
00032  *
00033  ***************************************************************************/
00034 
00035 
00036 class DiscMeta {
00037 
00038 public:
00039   // useful typedefs
00040   typedef pair<int, string *>         element_t;
00041   typedef vmap<int, element_t>        container_t;
00042   typedef container_t::iterator       iterator;
00043   typedef container_t::const_iterator const_iterator;
00044   typedef container_t::value_type     value_type;
00045 
00046 public:
00047   // Constructor: specify the meta file filename.  The constructor
00048   // will parse the contents and store the results.
00049   DiscMeta(const char *fname);
00050 
00051   // Destructor.
00052   ~DiscMeta();
00053 
00054   //
00055   // accessor functions
00056   //
00057 
00058   // return the config filename
00059   const string &getFilename() const { return MetaFile; }
00060 
00061   // return the number of valid lines in the file
00062   unsigned int size() const { return Lines.size(); }
00063 
00064   // return the line number of the Nth valid line (in range 1 ... M)
00065   int getLineNumber(unsigned int) const;
00066 
00067   // return the keyword of the Nth line
00068   const string &getKeyword(unsigned int);
00069 
00070   // return the number of words in the value for the Nth line
00071   int getNumWords(unsigned int) const;
00072 
00073   // return the list of words in the Nth line
00074   string *getWords(unsigned int);
00075 
00076   // return begin/end iterators for iterating over the list of lines
00077   iterator begin() { return Lines.begin(); }
00078   iterator end() { return Lines.end(); }
00079   const_iterator begin() const { return Lines.begin(); }
00080   const_iterator end() const { return Lines.end(); }
00081 
00082   // print out debugging information
00083   void printDebug(Inform &);
00084 
00085 private:
00086   // the name of the meta file
00087   string MetaFile;
00088 
00089   // the data for the lines themselves
00090   container_t Lines;
00091 
00092   // the storage for the keywords
00093   // read a single meta line, and return an array of strings as tokens
00094   bool read_meta_line(FILE*, string *&, int &);
00095 };
00096 
00097 #endif // DISC_META_H
00098 
00099 /***************************************************************************
00100  * $RCSfile: DiscMeta.h,v $   $Author: adelmann $
00101  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00102  * IPPL_VERSION_ID: $Id: DiscMeta.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00103  ***************************************************************************/

Generated on Mon Jan 16 13:23:58 2006 for IPPL by  doxygen 1.4.6