mimeio.h

Go to the documentation of this file.
00001 ///
00002 /// \file       mimeio.h
00003 ///             Storage, parser, builder classes for MIME objects
00004 ///             (vcard, vevent, vtodo, vjournal)
00005 ///
00006 
00007 /*
00008     Copyright (C) 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)
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     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_MIMEIO_H__
00024 #define __BARRY_MIMEIO_H__
00025 
00026 #include "dll.h"
00027 #include "builder.h"
00028 #include "vcard.h"
00029 #include "vevent.h"
00030 #include "vjournal.h"
00031 #include "vtodo.h"
00032 #include <string>
00033 #include <vector>
00034 #include <memory>
00035 #include <iostream>
00036 
00037 namespace Barry {
00038 
00039 class Contact;
00040 class Calendar;
00041 class Memo;
00042 class Task;
00043 
00044 //
00045 // Template classes to write MIME data to stream, from record.
00046 //
00047 
00048 template <class Record>
00049 class MimeDump
00050 {
00051 public:
00052         static void Dump(std::ostream &os, const Record &rec)
00053         {
00054                 os << rec << std::endl;
00055         }
00056 
00057         static bool Supported() { return false; }
00058 };
00059 
00060 template <>
00061 class MimeDump<Barry::Contact>
00062 {
00063 public:
00064         static void Dump(std::ostream &os, const Barry::Contact &rec)
00065         {
00066                 Barry::Sync::vCard vcard;
00067                 os << vcard.ToVCard(rec) << std::endl;
00068         }
00069 
00070         static bool Supported() { return true; }
00071 };
00072 
00073 template <>
00074 class MimeDump<Barry::Calendar>
00075 {
00076 public:
00077         static void Dump(std::ostream &os, const Barry::Calendar &rec)
00078         {
00079                 Barry::Sync::vTimeConverter vtc;
00080                 Barry::Sync::vCalendar vcal(vtc);
00081                 os << vcal.ToVCal(rec) << std::endl;
00082         }
00083 
00084         static bool Supported() { return true; }
00085 };
00086 
00087 template <>
00088 class MimeDump<Barry::Memo>
00089 {
00090 public:
00091         static void Dump(std::ostream &os, const Barry::Memo &rec)
00092         {
00093                 Barry::Sync::vTimeConverter vtc;
00094                 Barry::Sync::vJournal vjournal(vtc);
00095                 os << vjournal.ToMemo(rec) << std::endl;
00096         }
00097 
00098         static bool Supported() { return true; }
00099 };
00100 
00101 template <>
00102 class MimeDump<Barry::Task>
00103 {
00104 public:
00105         static void Dump(std::ostream &os, const Barry::Task &rec)
00106         {
00107                 Barry::Sync::vTimeConverter vtc;
00108                 Barry::Sync::vTodo vtodo(vtc);
00109                 os << vtodo.ToTask(rec) << std::endl;
00110         }
00111 
00112         static bool Supported() { return true; }
00113 };
00114 
00115 
00116 //
00117 // Builder class, for reading MIME stream data and loading into
00118 // a DBData record.
00119 //
00120 
00121 class BXEXPORT MimeBuilder : public Barry::Builder
00122 {
00123         std::auto_ptr<std::ifstream> m_ifs;
00124         std::istream &m_is;
00125 
00126 public:
00127         explicit MimeBuilder(const std::string &filename);
00128         explicit MimeBuilder(std::istream &is);
00129 
00130         bool BuildRecord(DBData &data, size_t &offset, const IConverter *ic);
00131         bool FetchRecord(DBData &data, const IConverter *ic);
00132         bool EndOfFile() const;
00133 
00134         // return false at end of file, true if a record was read
00135         static bool ReadMimeRecord(std::istream &is, std::string &vrec,
00136                                 std::vector<std::string> &types);
00137         // returns true if item is a member of types, doing a
00138         // case-insensitive compare
00139         static bool IsMember(const std::string &item,
00140                                 const std::vector<std::string> &types);
00141 };
00142 
00143 }
00144 
00145 #endif
00146