Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  
field.h
00001 /***************************************************************************
00002     copyright            : (C) 2002-2008 by Stefano Barbato
00003     email                : stefano@codesink.org
00004 
00005     $Id: field.h,v 1.14 2008-10-07 11:06:26 tat Exp $
00006  ***************************************************************************/
00007 #ifndef _MIMETIC_RFC822_FIELD_H_
00008 #define _MIMETIC_RFC822_FIELD_H_
00009 #include <string>
00010 #include <mimetic/strutils.h>
00011 #include <mimetic/rfc822/fieldvalue.h>
00012 
00013 namespace mimetic
00014 {
00015 
00016 
00017 
00018 /// Field class as defined by RFC822
00019 /**
00020     Field class is a C++ representation of RFC822 \e header \e field.
00021     Use this class when you need to create or parse messages' header fields.
00022     Note that field name is case insensitive.
00023 
00024     Parsing:
00025     \code
00026     Rfc822::Field f1("X-My-Field: some text(with a trailing comment)");
00027     cout << f.name() << endl;
00028     cout << f.value() << endl;
00029     cout << f.value(true) << endl; // canonicalize (see RFC822)
00030     \endcode
00031 
00032     Building:
00033     \code
00034     Rfc822::Field f;
00035     f.name("X-Unknown");
00036     f.value("some text(with a trailing comment)");
00037     cout << f;
00038     \endcode
00039 
00040     \sa <a href="../RFC/rfc822.txt">RFC822</a>
00041  */
00042 struct Field
00043 {
00044     typedef mimetic::istring istring;
00045     static const Field null;
00046     Field();
00047     Field(const std::string&);
00048     Field(const std::string&, const std::string&);
00049     ~Field();
00050 
00051     Field(const Field&);
00052     Field& operator=(const Field&);
00053 
00054     void name(const std::string&);
00055     const istring& name() const;
00056 
00057     void value(const std::string&);
00058     std::string value() const;
00059 
00060     std::ostream& write(std::ostream&, unsigned int fold = 0) const;
00061     friend std::ostream& operator<<(std::ostream&, const Field&);
00062 private:
00063     friend class Rfc822Header;
00064     istring m_name;
00065     FieldValue* m_pValue;
00066 };
00067 
00068 
00069 }
00070 #endif