OpenMining  0.01
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
load.h
Go to the documentation of this file.
1 #ifndef load_h
2 #define load_h
3 
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 
8 // boost includes
9 #include <boost/archive/text_iarchive.hpp>
10 
11 namespace utils
12 {
13  template <class Tobject, class Tfilename>
14  bool load(Tobject& object, Tfilename filename)
15  {
16  bool retval = false;
17  if (filename == "")
18  {
19  std::cerr << "Error: trying to restore an object from a nameless file" << std::endl;
20  }
21  else
22  {
23  std::ifstream ifs (filename);
24 
25  if (ifs.good())
26  {
27  std::cout << __PRETTY_FUNCTION__ << "loading object from file '" << filename << "'" << std::endl;
28  boost::archive::text_iarchive ia(ifs);
29  ia >> object;
30  retval = true;
31  }
32  else
33  {
34  std::cerr << __PRETTY_FUNCTION__ << " Error loading object from file '" << filename << "'" << std::endl;
35  }
36  }
37  return (retval);
38  }
39 
40  template <class Tobject, class Tfilename>
41  bool load(Tobject* object, Tfilename& filename)
42  {
43  return (load (*object, filename));
44  }
45 
46  template <class Tobject>
47  bool load(Tobject* object, const char* filename)
48  {
49  return (load (*object, std::string(filename)));
50  }
51 }
52 
53 #endif
bool load(Tobject &object, Tfilename filename)
Definition: load.h:14