Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  

field.h

00001 /***************************************************************************
00002     copyright            : (C) 2002-2005 by Stefano Barbato
00003     email                : [email protected]
00004 
00005     $Id: field_8h-source.html,v 1.4 2006-03-12 12:28:31 tat Exp $
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _MIMETIC_RFC822_FIELD_H_
00017 #define _MIMETIC_RFC822_FIELD_H_
00018 #include <string>
00019 #include <mimetic/strutils.h>
00020 #include <mimetic/rfc822/fieldvalue.h>
00021 
00022 namespace mimetic
00023 {
00024 
00025 
00026 
00027 /// Field class as defined by RFC822
00028 /**
00029     Field class is a C++ representation of RFC822 \e header \e field.
00030     Use this class when you need to create or parse messages' header fields.
00031     Note that field name is case insensitive.
00032 
00033     Parsing:
00034     \code
00035     Rfc822::Field f1("X-My-Field: some text(with a trailing comment)");
00036     cout << f.name() << endl;
00037     cout << f.value() << endl;
00038     cout << f.value(true) << endl; // canonicalize (see RFC822)
00039     \endcode
00040 
00041     Building:
00042     \code
00043     Rfc822::Field f;
00044     f.name("X-Unknown");
00045     f.value("some text(with a trailing comment)");
00046     cout << f;
00047     \endcode
00048 
00049     \sa <a href="../RFC/rfc822.txt">RFC822</a>
00050  */
00051 struct Field
00052 {
00053     typedef mimetic::istring istring;
00054     static const Field null;
00055     Field();
00056     Field(const std::string&);
00057     Field(const std::string&, const std::string&);
00058     ~Field();
00059 
00060     Field(const Field&);
00061     Field& operator=(const Field&);
00062 
00063     void name(const std::string&);
00064     const istring& name() const;
00065 
00066     void value(const std::string&);
00067     std::string value() const;
00068 
00069     std::ostream& write(std::ostream&, unsigned int fold = 0) const;
00070     friend std::ostream& operator<<(std::ostream&, const Field&);
00071 private:
00072     friend class Rfc822Header;
00073     istring m_name;
00074     FieldValue* m_pValue;
00075 };
00076 
00077 
00078 }
00079 #endif