value.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_VALUE_H
00019 #define XDKBIB_VALUE_H
00020 
00021 #if HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <xdkbibtex/base.h>
00026 
00027 #include <string>
00028 #include <vector>
00029 #include <iostream>
00030 #include <map>
00031 
00032 class valueparser;
00033 
00034 namespace xdkbib
00035 {
00036   class Text;
00037   class Word;
00038   class Letter;
00039   class SingleLetter;
00040   class PseudoLetter;
00041   class TokenLetter;
00042   class Dictionary;
00043 
00044   typedef enum
00045   {
00046     Raw             = 0,
00047     BracesStripped  = 1,
00048     CommandStripped = 2
00049   }
00050   ContentOptions;  
00051   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00052   // Interface of Text
00053   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00054   class Text
00055   {
00056   public:
00057     Text();
00058     Text* clone() const;
00059     Text& operator=(const Text&);
00060     Text(const Text&);    
00061     ~Text();
00062     
00063     void readFrom(const std::string& t,const std::string& split="")
00064       throw (xdkbib::parsing_error);
00065     
00066     std::string content(ContentOptions options=Raw) const;
00067     bool hasContent(const std::string& s,ContentOptions options=Raw) const;
00068     
00069     unsigned int nbWords() const;
00070     const Word* operator[](unsigned int i) const;
00071     const std::vector<Word*>& words() const;
00072 
00073     Word* add(Word* w=NULL);
00074     void clear();
00075     void translate(const Dictionary& dict);
00076   protected:
00077     friend class ::valueparser;
00078   private:
00079     std::vector<Word*> words_;
00080   };
00081   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00082   // Interface of Word
00083   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00084   class Word
00085   {
00086   public:
00087     Word();
00088     Word(const Word& w);
00089     Word& operator=(const Word& w);
00090     ~Word();
00091     Word* clone() const;
00092 
00093     std::string content(ContentOptions options=Raw) const;
00094     bool hasContent(const std::string& s,ContentOptions options=Raw) const;
00095 
00096     unsigned int nbLetters() const;
00097     const Letter* operator[](unsigned int i) const;
00098     const std::vector<Letter*>& letters() const;
00099 
00100     Letter* add(Letter* w);
00101     void clear();
00102 
00103     bool hasPseudoLetters() const;
00104   protected:
00105     friend class ::valueparser;
00106     friend class Text;
00107   private:
00108     std::vector<Letter*> letters_;
00109   };
00110   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00111   // Interface of Word
00112   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00113   class Letter
00114   {
00115   public:
00116     virtual ~Letter() {}
00117     virtual Letter* clone() const = 0;
00118     
00119     virtual std::string content(ContentOptions options=Raw) const = 0;
00120     bool hasContent(const std::string& s,ContentOptions options=Raw) const;
00121     
00122     virtual bool isSingle() const;
00123     virtual bool isPseudo() const;
00124     virtual bool isToken() const;
00125 
00126     virtual const SingleLetter* asSingle() const;
00127     virtual const PseudoLetter* asPseudo() const;
00128     virtual const TokenLetter* asToken() const;
00129 
00130     virtual bool isTheSingle(char) const;
00131     virtual bool isTheToken(const std::string& s) const;
00132     
00133   protected:
00134     friend class Text;
00135     friend class Word;
00136   };
00137   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00138   // Interface or SingleLetter
00139   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00140   class SingleLetter : public Letter
00141   {
00142   public:
00143     SingleLetter(char c);
00144     virtual Letter* clone() const;
00145     char character() const;
00146 
00147     virtual std::string content(ContentOptions options) const;
00148 
00149     virtual bool isSingle() const;
00150     virtual const SingleLetter* asSingle() const;
00151     virtual bool isTheSingle(char) const;
00152   protected:
00153     friend class ::valueparser;
00154     friend class Text;
00155     friend class Word;
00156   private:
00157     char c_;
00158   };
00159   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00160   // Interface or PseudoLetter
00161   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00162   class PseudoLetter : public Letter
00163   {
00164   public:
00165     PseudoLetter();
00166     virtual Letter* clone() const;
00167     virtual ~PseudoLetter();
00168     virtual const Text* text() const;
00169     
00170     virtual std::string content(ContentOptions options) const;
00171 
00172     virtual bool isPseudo() const;
00173     virtual const PseudoLetter* asPseudo() const;
00174   protected:
00175     friend class ::valueparser;
00176     friend class Text;
00177     friend class Word;
00178   private:
00179     Text* text_;
00180   };
00181   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00182   // Interface or TokenLetter
00183   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00184   class TokenLetter : public Letter
00185   {
00186   public:
00187     TokenLetter(const std::string&);
00188     virtual Letter* clone() const;
00189     const std::string& token() const;
00190 
00191     virtual std::string content(ContentOptions options) const;
00192 
00193     virtual bool isToken() const;
00194     virtual const TokenLetter* asToken() const;    
00195     virtual bool isTheToken(const std::string& s) const;
00196   protected:
00197     friend class ::valueparser;
00198     friend class Text;
00199     friend class Word;
00200   private:
00201     std::string token_;
00202   };
00203   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00204   // Interface of Dictionary
00205   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00206   class Dictionary : public std::map<std::pair<std::string,std::string>,std::string>
00207   {
00208   public:
00209   };
00210   extern const Dictionary& isoaccents();
00211 }
00212 
00213 #endif // XDKBIB_VALUE_H

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