Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

header.h

Go to the documentation of this file.
00001 /* 
00002  * This file is part of the rfc822 library (C) rebel42@users.sourceforge.net.
00003  *
00004  * The rfc822 library is released under the terms of the GNU Library General Public License as
00005  * published by the Free Software Foundation; either version 2 of the
00006  * License, or (at your option) any later version. See the file COPYING
00007  * as included in the distribution for details.
00008  */
00009 #ifndef RFC822_HEADER_H
00010 #define RFC822_HEADER_H
00011 
00012 #include <string>
00013 #include <list>
00014 #include <map>
00015 
00016 using namespace std;
00017 
00018 namespace rfc822
00019 {
00020 
00021 class parser;
00022 class msg;
00023 
00025 
00062 class header
00063 {
00064         typedef map<string, string> Map;
00065         map<string, string>     m_sorted;
00066         
00067 public:
00069         header()
00070                 { }
00071                 
00073         header(const string& h)
00074                 { operator = (h); }
00075 
00077         header(const header& h): m_sorted(h.m_sorted)
00078                 { }
00079 
00081         header(const msg& h);
00082 
00084         header& operator = (const header& h)
00085                 { m_sorted = h.m_sorted; return *this; }
00086         
00088 
00095         header& operator = (const string& h);
00096         
00098 
00108         const string& operator[](const string& id) const
00109                 { return getEntry(id); }
00110 
00112         class entry: public string
00113         {
00114                 header&                 h;
00115                 const string&   id;
00116                 string                  initial;
00117 
00118         private:
00119                 entry& operator = (const entry&);
00120         
00121         public:
00122                 entry(const string& value, header& header, const string& i): 
00123                         string(value), h(header), id(i), initial(value)
00124                         { }
00125 
00126                 entry(const entry& entry): string(entry), h(entry.h), 
00127                         id(entry.id), initial(entry.initial)
00128                         { }
00129                         
00130                 ~entry()
00131                         { if(*this != initial) h.setEntry(id, *this); }
00132                         
00133                 entry& operator = (const string& s) 
00134                         { string::operator = (s); return *this; }
00135                 entry& operator += (const string& s)
00136                 { 
00137                         if(length()) { append("\n ", 2); append(s); }
00138                         else string::operator = (s); 
00139                         return *this; 
00140                 }
00141         };
00142 
00143         entry operator[](const string& name)
00144                 { return entry(getEntry(name), *this, name); }
00145 
00146 private:
00147         friend class header::entry;
00148         
00149         const string& getEntry(const string& id) const;
00150         void setEntry(const string& id, const string& str);
00151         
00152 private:
00153         friend class parser;
00154         
00155         static map<string, parser*> m_parsers;
00156         static list<string> listParsers(parser* p = 0);
00157 
00158         static void registerParser(parser*, const string& name);
00159         static void unregisterParser(parser*);
00160 
00161         static parser* findParser(const string& name);
00162 
00163         void parseEntry(const char* buf, int len);
00164 
00165         friend ostream& operator << (ostream&, const header&);
00166 };
00167 
00168 ostream& operator << (ostream&, const header&);
00169 
00170 }; // namespace
00171 
00172 #endif

Generated on Mon Oct 22 17:03:48 2001 for rfc822 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001