GCOP
1.0
|
00001 #ifndef GCOP_PARAMS_H 00002 #define GCOP_PARAMS_H 00003 00004 #include <map> 00005 #include <cstring> 00006 #include <iostream> 00007 #include <Eigen/Dense> 00008 00009 /* 00010 * Provides storage and retrieval for arbitrary 00011 * number of parameters of different types (currently only primitives and strings) 00012 * TODO: include matrix parameter 00013 * Parameters can be loaded/saved from/to a file, or can be inserted at run-time 00014 * 00015 * 00016 * Author: Marin Kobilarov (mkobilar@@robotics.usc.edu) 00017 */ 00018 00019 namespace gcop { 00020 00021 using namespace Eigen; 00022 00023 #define GCOP_PARAMS_MBL 256 00024 00025 typedef Matrix<double, 6, 6> Matrix6d; 00026 typedef Matrix<double, 6, 1> Vector6d; 00027 typedef Matrix<double, 5, 5> Matrix5d; 00028 typedef Matrix<double, 5, 1> Vector5d; 00029 00030 00031 class Params 00032 { 00033 public: 00034 00035 Params(); 00036 Params(FILE *file); 00037 Params(const char *fileName); 00038 Params(std::iostream &io); 00039 00040 virtual ~Params(); 00041 00042 void Load(const char *fileName); 00043 void Load(FILE *file); 00044 void Load(std::iostream &io); 00045 00046 void Save(const char *fileName) const; 00047 void Save(FILE* file) const; 00048 void Save(std::iostream &io) const; 00049 00050 bool Exists(const char *name) const { return valueMap.find(std::string(name)) != valueMap.end(); } 00051 00052 void SetInt(const char *name, int v); 00053 bool GetInt(const char *name, int &v) const; 00054 00055 void SetFloat(const char *name, float v); 00056 bool GetFloat(const char *name, float &v) const; 00057 00058 void SetDouble(const char *name, double v); 00059 bool GetDouble(const char *name, double &v) const; 00060 00061 void SetVectorXd(const char *name, const VectorXd &v); 00062 bool GetVectorXd(const char *name, VectorXd &v) const; 00063 00064 void SetVector2d(const char *name, const Vector2d &v); 00065 bool GetVector2d(const char *name, Vector2d &v) const; 00066 00067 void SetVector3d(const char *name, const Vector3d &v); 00068 bool GetVector3d(const char *name, Vector3d &v) const; 00069 00070 void SetVector4d(const char *name, const Vector4d &v); 00071 bool GetVector4d(const char *name, Vector4d &v) const; 00072 00073 void SetVector5d(const char *name, const Vector5d &v); 00074 bool GetVector5d(const char *name, Vector5d &v) const; 00075 00076 void SetVector6d(const char *name, const Vector6d &v); 00077 bool GetVector6d(const char *name, Vector6d &v) const; 00078 00079 void SetMatrix3d(const char *name, const Matrix3d &m); 00080 bool GetMatrix3d(const char *name, Matrix3d &m) const; 00081 00082 void SetMatrix6d(const char *name, const Matrix6d &m); 00083 bool GetMatrix6d(const char *name, Matrix6d &m) const; 00084 00085 void SetDoubleVec(const char *name, const std::vector<double> &v); 00086 bool GetDoubleVec(const char *name, std::vector<double> &v) const; 00087 00088 void SetFloatArray(const char *name, int n, const float *v); 00089 bool GetFloatArray(const char *name, int n, float *v) const; 00090 00091 void SetDoubleArray(const char *name, int n, const double *v); 00092 bool GetDoubleArray(const char *name, int n, double *v) const; 00093 00094 void SetString(const char *name, const std::string &v); 00095 bool GetString(const char *name, std::string &v) const; 00096 00097 void SetBool(const char *name, bool v); 00098 bool GetBool(const char *name, bool &v) const; 00099 00100 void SetChar(const char *name, char v); 00101 char GetChar(const char *name, char &v) const; 00102 00103 void Print(FILE *file = stdout) const; 00104 void Print(std::iostream &io) const; 00105 00106 protected: 00107 00108 00109 struct RemoveDelimiter 00110 { 00111 bool operator()(char c) 00112 { 00113 return (c =='\r' || c =='\t' || c == ' ' || c == '\n'); 00114 } 00115 }; 00116 00117 00118 void Parse(char *line); 00119 00120 std::map<std::string, std::string> valueMap; 00121 char buf[GCOP_PARAMS_MBL]; 00122 }; 00123 00124 } 00125 00126 #endif