file.h

Go to the documentation of this file.
00001 // Copyright (C) 2004 Xavier Décoret <Xavier.Decoret@imag.fr>
00002 
00003 // This program is free software; you can redistribute it and/or 
00004 // modify it under the terms of the GNU General Public License 
00005 // as published by the Free Software Foundation; either 
00006 // version 2 of the License, or (at your option) any later 
00007 // version.
00008 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 #ifndef XDKBIB_FILE_H
00019 #define XDKBIB_FILE_H
00020 
00021 #if HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <xdkbibtex/base.h>
00026 #include <xdkbibtex/entry.h>
00027 
00028 #include <vector>
00029 #include <map>
00030 #include <string>
00031 #include <stdexcept>
00032 
00033 namespace xdkbib
00034 {
00035         class File;
00036   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00037   // Interface of FileEntry
00038   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00039   class FileEntry : public Entry
00040   {
00041   public:
00042     FileEntry();
00043   protected:
00044     friend class File;
00045     FileEntry(const Entry& e,const File* f);
00046     virtual std::string valueOf(const std::string& s) const;
00047   private:
00048     const File* file_;
00049   };
00050   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00051   // Interface of File
00052   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00053   class File
00054   {
00055   public:
00056     typedef enum
00057     {
00058       StrictQuote       = 0,
00059       WarnQuote         = 1,
00060       AcceptQuote       = 2,
00061     };
00062     File();
00063     ~File();
00064     void readFromFile(const std::string& fileName,
00065                       int options=StrictQuote)
00066       throw(xdkbib::parsing_error);
00067 
00068     const std::vector<std::vector<ValuePart> >& preambleComponents() const;
00069     const std::vector<FileEntry>& entries() const;
00070     const std::map<std::string,std::vector<ValuePart> >& strings() const;
00071     std::string preamble() const;    
00072     std::string  stringText(const std::string& s,bool nothrow=true) const
00073       throw(std::range_error);
00074     const std::string& comment() const;
00075     void setComment(const std::string&);
00076   
00077 
00078     void clearPreamble();
00079     File& addToPreamble(const ValuePart& p,bool newline=true);
00080     FileEntry* addEntry(const Entry& e);
00081     void clearEntries();
00082     template <class O>
00083     void defineString(const std::string& s,O first,const O& last);
00084     File& addToString(const std::string& s,const ValuePart& p);
00085     void clearStrings();
00086   private:
00087     std::vector<std::vector<ValuePart> >          preambleComponents_;
00088     std::vector<FileEntry>                        entries_;
00089     std::map<std::string,std::vector<ValuePart> > strings_;
00090     std::string                                   comment_;
00091   };
00092   //************************************************************
00093   // Implementation of File
00094   //************************************************************
00095   template <class O>
00096   void
00097   File::defineString(const std::string& s,O first,const O& last)
00098   {
00099     // TODO: check if it exists already?
00100     strings_[s] = std::vector<ValuePart>(first,last);
00101   }
00102 }
00103 
00104 #endif // XDKBIB_FILE_H

Generated on Wed Jan 24 01:14:42 2007 for XDKBIBTEX by  doxygen 1.5.1