lib: fixed parsing of recurring VEVENTS: DAILY and interval support
[barry/progweb.git] / tools / boostwrap.cc
blob81cf6c0336d287de1cf47fa60a0bf7b6223dcc05
1 ///
2 /// \file boostwrap.cc
3 /// Wrap Boost serialization into its own lib, so each usage
4 /// in the tools doesn't cause a compile speed meltdown.
5 ///
7 /*
8 Copyright (C) 2012, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include "boostwrap.h"
25 using namespace std;
26 using namespace Barry;
28 #ifdef __BARRY_BOOST_MODE__
30 template <class RecordT>
31 bool DoLoadBoostFile(const std::string &filename,
32 std::vector<RecordT> &container,
33 std::string &dbName,
34 std::string &errmsg)
36 try {
37 std::ifstream ifs(filename.c_str());
38 std::getline(ifs, dbName);
39 boost::archive::text_iarchive ia(ifs);
40 ia >> container;
41 return true;
43 catch( boost::archive::archive_exception &ae ) {
44 errmsg = "Archive exception in DoLoadBoostFile(): ";
45 errmsg += ae.what();
46 return false;
50 template <class RecordT>
51 bool DoSaveBoostFile(const std::string &filename,
52 const std::vector<RecordT> &container,
53 std::string &errmsg)
55 try {
56 std::ofstream ofs(filename.c_str());
57 ofs << RecordT::GetDBName() << endl;
58 boost::archive::text_oarchive oa(ofs);
59 oa << container;
60 return true;
62 catch( boost::archive::archive_exception &ae ) {
63 errmsg = "Archive exception in DoSaveBoostFile(): ";
64 errmsg += ae.what();
65 return false;
69 #undef HANDLE_PARSER
70 #define HANDLE_PARSER(tname) \
71 bool LoadBoostFile(const std::string &filename, \
72 std::vector<tname> &container, \
73 std::string &dbName, \
74 std::string &errmsg) \
75 { \
76 return DoLoadBoostFile<tname>(filename, container, dbName, errmsg); \
77 } \
78 bool SaveBoostFile(const std::string &filename, \
79 const std::vector<tname> &container, \
80 std::string &errmsg) \
81 { \
82 return DoSaveBoostFile<tname>(filename, container, errmsg); \
84 ALL_KNOWN_PARSER_TYPES
86 #endif