00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
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
00094
00095 template <class O>
00096 void
00097 File::defineString(const std::string& s,O first,const O& last)
00098 {
00099
00100 strings_[s] = std::vector<ValuePart>(first,last);
00101 }
00102 }
00103
00104 #endif // XDKBIB_FILE_H