Biorbd Release_1.13.0
Loading...
Searching...
No Matches
IfStream.h
1#ifndef BIORBD_UTILS_IFSTREAM_H
2#define BIORBD_UTILS_IFSTREAM_H
3
4#include "biorbdConfig.h"
5
6#include <iostream>
7#include <map>
8
9#include "Utils/Path.h"
10#include "rbdl/rbdl_math.h"
11
12namespace BIORBD_NAMESPACE {
13namespace utils {
14class Equation;
15class Vector3d;
16
20class BIORBD_API IfStream {
21 public:
25 IfStream();
26
32 IfStream(const Path& path, std::ios_base::openmode mode);
33
39 IfStream(const char* path, std::ios_base::openmode mode);
40
47 bool open(const Path& path, std::ios_base::openmode mode);
48
54 bool read(String& text);
55
61 bool readAWord(String& text);
62
68 bool read(int& val);
69
75 bool read(bool& val);
76
82 bool read(size_t& val);
83
89 bool read(double& val);
90#ifdef BIORBD_USE_CASADI_MATH
96 bool read(RBDLCasadiMath::MX_Xd_SubMatrix val);
97#endif
98
105 bool read(double& result, const std::map<Equation, double>& variables);
106#ifdef BIORBD_USE_CASADI_MATH
113 bool read(
114 RBDLCasadiMath::MX_Xd_SubMatrix result,
115 const std::map<Equation, double>& variables);
116#endif
117
124 bool readFromBinary(char* output, int n_elements);
125
131 bool readFromBinary(float& result);
132
138 bool readFromBinary(Vector3d& v);
139
146 bool readSpecificTag(const String& tag, String& text);
147
154 bool reachSpecificTag(const String& tag, size_t maxTag = -1);
155
162 int countTagsInAConsecutiveLines(const String& tag);
163
168 void getline(String& text);
169
173 void resetCursor();
174
179 bool close();
180
185 bool eof();
186
187 protected:
188 std::shared_ptr<bool> m_isOpen;
189 char m_floatBuffer[sizeof(float)];
190
191 private:
192 std::shared_ptr<std::ifstream> m_ifs;
193 std::shared_ptr<Path> m_path;
194};
195
196} // namespace utils
197} // namespace BIORBD_NAMESPACE
198
199#endif // BIORBD_UTILS_IFSTREAM_H
Strings that are to be interpreted as equation that can be evaluated.
Definition Equation.h:17
bool reachSpecificTag(const String &tag, size_t maxTag=-1)
Advance in the file to a specific tag.
Definition IfStream.cpp:58
bool close()
Close the file.
Definition IfStream.cpp:220
bool eof()
Return if the file is at the end.
Definition IfStream.cpp:225
int countTagsInAConsecutiveLines(const String &tag)
Counts the number of consecutive lines starting with the same tag and then brings it back to the init...
Definition IfStream.cpp:80
char m_floatBuffer[sizeof(float)]
Buffer for reading float in binaries.
Definition IfStream.h:189
bool readFromBinary(char *output, int n_elements)
Read a certain amounts of bits in binary.
Definition IfStream.cpp:152
std::shared_ptr< bool > m_isOpen
If file is open.
Definition IfStream.h:188
bool readSpecificTag(const String &tag, String &text)
Advance in the file to a specific tag.
Definition IfStream.cpp:51
IfStream()
Construct IfStream.
Definition IfStream.cpp:14
void getline(String &text)
Read a whole line.
Definition IfStream.cpp:210
bool open(const Path &path, std::ios_base::openmode mode)
Open the file.
Definition IfStream.cpp:40
bool readAWord(String &text)
Read a word in the file.
Definition IfStream.cpp:123
bool read(String &text)
Read a word in the file skipping the word if it is c-like commented.
Definition IfStream.cpp:101
void resetCursor()
Reset the file cursor to the 0 position.
Definition IfStream.cpp:214
Collection of methods to manipulate path.
Definition Path.h:16
Wrapper around the std::string class with augmented functionality.
Definition String.h:18
Wrapper around Eigen Vector3d and attach it to a parent.
Definition Vector3d.h:27