Skip to content

Commit

Permalink
Documented HDA_OfstreamWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoesmp committed Sep 18, 2023
1 parent 59339e4 commit cf5b171
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/dataanalytics/HDA_OfstreamWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,32 @@ class HDA_OfstreamWrapper{
protected:
// *** ATTRIBUTES *** //
// ******************** //
/**
* @brief The output file stream used to write to a file.
*/
std::ofstream ofs;
/**
* @brief The separator between recorded elements
* @brief The separator between recorded elements.
*/
std::string sep;
/**
* @brief Boolean flag to control whether the HDA_OfstreamWrapper has
* written something or not. Once something has been written, the flag
* will be set to true. By default, it is initialized to false.
*/
bool hasWrittenSomething;

public:
// *** CONSTRUCTION / DESTRUCTION *** //
// ************************************ //
HDA_OfstreamWrapper(std::string const &outpath, std::string const &sep=",") :
/**
* @brief Build a HDA_OfstreamWrapper to handle writing records to files.
* @param outpath The path to the output file.
* @see HDA_OfstreamWrapper::sep
*/
HDA_OfstreamWrapper(
std::string const &outpath, std::string const &sep=","
) :
ofs(outpath, std::ios_base::out),
sep(sep),
hasWrittenSomething(false)
Expand All @@ -31,11 +46,24 @@ class HDA_OfstreamWrapper{

// *** OUTPUT FILE STREAM METHODS *** //
// ************************************ //
/**
* @brief Wraps the is_open method of the output file stream class.
*/
inline bool is_open() {return ofs.is_open();}
/**
* @brief Wraps the close method of the output file stream class.
*/
inline void close() {return ofs.close();}

// *** OUTPUT FILE STREAM OPERATORS *** //
// ************************************** //
/**
* @brief Default stream input operator, i.e., <<.
* @tparam T The type of element to be written.
* @param elem The element to be written.
* @return A reference to the HDA_OfstreamWrapper itself for fluent
* programming purposes.
*/
template <typename T>
HDA_OfstreamWrapper & operator <<(T const &elem){
if(hasWrittenSomething){
Expand All @@ -48,6 +76,12 @@ class HDA_OfstreamWrapper{
return *this;
}

/**
* @brief Stream input operator to handle vectors of doubles as element.
* @param elem The vector of doubles as element.
* @return A reference to the HDA_OfstreamWrapper itself for fluent
* programming purposes.
*/
HDA_OfstreamWrapper & operator <<(std::vector<double> const &elem){
ofs << elem[0];
for(size_t i = 1 ; i < elem.size(); ++i){
Expand Down

0 comments on commit cf5b171

Please sign in to comment.