MLPACK  1.0.11
save_restore_utility.hpp
Go to the documentation of this file.
1 
25 #ifndef __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_HPP
26 #define __MLPACK_CORE_UTIL_SAVE_RESTORE_UTILITY_HPP
27 
28 #include <mlpack/prereqs.hpp>
29 #include <list>
30 #include <map>
31 #include <sstream>
32 #include <string>
33 
34 #include <libxml/parser.h>
35 #include <libxml/tree.h>
36 
37 #include <boost/tokenizer.hpp>
38 
39 namespace mlpack {
40 namespace util {
41 
43 {
44  private:
48  std::map<std::string, std::string> parameters;
49 
53  void RecurseOnNodes(xmlNode* n);
54 
55  public:
57  ~SaveRestoreUtility() { parameters.clear(); }
58 
62  bool ReadFile(const std::string& filename);
63 
67  bool WriteFile(const std::string& filename);
68 
72  template<typename T>
73  T& LoadParameter(T& t, const std::string& name);
74 
78  template<typename T>
79  std::vector<T>& LoadParameter(std::vector<T>& v, const std::string& name);
80 
84  char LoadParameter(char c, const std::string& name);
85 
89  std::string LoadParameter(std::string& str, const std::string& name);
90 
94  arma::mat& LoadParameter(arma::mat& matrix, const std::string& name);
95 
99  template<typename T>
100  void SaveParameter(const T& t, const std::string& name);
101 
102 
103 
107  template<typename T>
108  void SaveParameter(const std::vector<T>& v, const std::string& name);
109 
113  void SaveParameter(const char c, const std::string& name);
114 
118  void SaveParameter(const arma::mat& mat, const std::string& name);
119 };
120 
122 template<>
123 arma::vec& SaveRestoreUtility::LoadParameter(arma::vec& t,
124  const std::string& name);
125 
127 template<>
128 void SaveRestoreUtility::SaveParameter(const arma::vec& t,
129  const std::string& name);
130 
131 }; /* namespace util */
132 }; /* namespace mlpack */
133 
134 // Include implementation.
135 #include "save_restore_utility_impl.hpp"
136 
137 #endif
void SaveParameter(const T &t, const std::string &name)
SaveParameter saves a parameter to the parameters map.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
The core includes that mlpack expects; standard C++ includes and Armadillo.
void RecurseOnNodes(xmlNode *n)
RecurseOnNodes performs a depth first search of the XML tree.
T & LoadParameter(T &t, const std::string &name)
LoadParameter loads a parameter from the parameters map.
std::map< std::string, std::string > parameters
parameters contains a list of names and parameters in string form.
bool ReadFile(const std::string &filename)
ReadFile reads an XML tree from a file.
bool WriteFile(const std::string &filename)
WriteFile writes the XML tree to a file.