Bumped copyright dates for 2013
[barry.git] / tools / boostwrap.cc
blob766406182f71badd07c56cc9060cf037967ce436
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-2013, 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"
24 #include "i18n.h"
26 using namespace std;
27 using namespace Barry;
29 #ifdef __BARRY_BOOST_MODE__
31 template <class RecordT>
32 bool DoLoadBoostFile(const std::string &filename,
33 std::vector<RecordT> &container,
34 std::string &dbName,
35 std::string &errmsg)
37 try {
38 std::ifstream ifs(filename.c_str());
39 std::getline(ifs, dbName);
40 boost::archive::text_iarchive ia(ifs);
41 ia >> container;
42 return true;
44 catch( boost::archive::archive_exception &ae ) {
45 errmsg = _("Archive exception in DoLoadBoostFile(): ");
46 errmsg += ae.what();
47 return false;
51 template <class RecordT>
52 bool DoSaveBoostFile(const std::string &filename,
53 const std::vector<RecordT> &container,
54 std::string &errmsg)
56 try {
57 std::ofstream ofs(filename.c_str());
58 ofs << RecordT::GetDBName() << endl;
59 boost::archive::text_oarchive oa(ofs);
60 oa << container;
61 return true;
63 catch( boost::archive::archive_exception &ae ) {
64 errmsg = _("Archive exception in DoSaveBoostFile(): ");
65 errmsg += ae.what();
66 return false;
70 #undef HANDLE_PARSER
71 #define HANDLE_PARSER(tname) \
72 bool LoadBoostFile(const std::string &filename, \
73 std::vector<tname> &container, \
74 std::string &dbName, \
75 std::string &errmsg) \
76 { \
77 return DoLoadBoostFile<tname>(filename, container, dbName, errmsg); \
78 } \
79 bool SaveBoostFile(const std::string &filename, \
80 const std::vector<tname> &container, \
81 std::string &errmsg) \
82 { \
83 return DoSaveBoostFile<tname>(filename, container, errmsg); \
85 ALL_KNOWN_PARSER_TYPES
87 #endif