src/utilities/filetypes/CSVFile_Impl.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_FILETYPES_CSVFILE_IMPL_HPP | ||
| 7 | #define UTILITIES_FILETYPES_CSVFILE_IMPL_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | |||
| 11 | #include "../core/Logger.hpp" | ||
| 12 | #include "../core/Path.hpp" | ||
| 13 | #include "../data/Vector.hpp" | ||
| 14 | |||
| 15 | namespace openstudio { | ||
| 16 | |||
| 17 | class CSVFile; | ||
| 18 | class Variant; | ||
| 19 | class DateTime; | ||
| 20 | |||
| 21 | namespace detail { | ||
| 22 | |||
| 23 | class UTILITIES_API CSVFile_Impl | ||
| 24 | { | ||
| 25 | public: | ||
| 26 | CSVFile_Impl(); | ||
| 27 | |||
| 28 | CSVFile_Impl(const std::string& s); | ||
| 29 | |||
| 30 | CSVFile_Impl(const openstudio::path& p); | ||
| 31 | |||
| 32 | CSVFile clone() const; | ||
| 33 | |||
| 34 | std::string string() const; | ||
| 35 | |||
| 36 | // cppcheck-suppress functionStatic | ||
| 37 | bool save() const; | ||
| 38 | |||
| 39 | bool saveAs(const openstudio::path& p); | ||
| 40 | |||
| 41 | boost::optional<openstudio::path> path() const; | ||
| 42 | |||
| 43 | bool setPath(const openstudio::path& path); | ||
| 44 | |||
| 45 | void resetPath(); | ||
| 46 | |||
| 47 | unsigned numColumns() const; | ||
| 48 | |||
| 49 | unsigned numRows() const; | ||
| 50 | |||
| 51 | std::vector<std::vector<Variant>> rows() const; | ||
| 52 | |||
| 53 | void addRow(const std::vector<Variant>& row); | ||
| 54 | |||
| 55 | void setRows(const std::vector<std::vector<Variant>>& rows); | ||
| 56 | |||
| 57 | void clear(); | ||
| 58 | |||
| 59 | /** Add a column of std::vector<DateTime>, returns column index (first column is index 0). */ | ||
| 60 | unsigned addColumn(const std::vector<DateTime>& dateTimes); | ||
| 61 | |||
| 62 | /** Add a column of values in a Vector, returns column index (first column is index 0). */ | ||
| 63 | unsigned addColumn(const Vector& values); | ||
| 64 | |||
| 65 | /** Add a column of values in a std::vector<double>, returns column index (first column is index 0). */ | ||
| 66 | unsigned addColumn(const std::vector<double>& values); | ||
| 67 | |||
| 68 | /** Add a column of values in a std::vector<std::string>, returns column index (first column is index 0). */ | ||
| 69 | unsigned addColumn(const std::vector<std::string>& values); | ||
| 70 | |||
| 71 | /** Get column of DateTime values (first column is index 0). Empty vector is returned if any cell is not a valid DateTime or if column index is invalid.*/ | ||
| 72 | std::vector<DateTime> getColumnAsDateTimes(unsigned columnIndex) const; | ||
| 73 | |||
| 74 | /** Get column as a Vector (first column is index 0). Empty vector is returned if any cell is not a valid number or if column index is invalid.*/ | ||
| 75 | std::vector<double> getColumnAsDoubleVector(unsigned columnIndex) const; | ||
| 76 | |||
| 77 | /** Get column as a Vector (first column is index 0). Numeric cells will be converted to strings. Empty vector is returned if column index is invalid.*/ | ||
| 78 | std::vector<std::string> getColumnAsStringVector(unsigned columnIndex) const; | ||
| 79 | |||
| 80 | private: | ||
| 81 | − | REGISTER_LOGGER("openstudio.CSVFile"); | |
| 82 | |||
| 83 | // throws on error | ||
| 84 | static std::vector<std::vector<Variant>> parseRows(std::istream& input); | ||
| 85 | |||
| 86 | void assignNumColumns(); | ||
| 87 | |||
| 88 | void ensureNumRows(unsigned numRows); | ||
| 89 | |||
| 90 | void padRows(); | ||
| 91 | |||
| 92 | boost::optional<openstudio::path> m_path; | ||
| 93 | unsigned m_numColumns; | ||
| 94 | std::vector<std::vector<Variant>> m_rows; | ||
| 95 | }; | ||
| 96 | |||
| 97 | } // namespace detail | ||
| 98 | } // namespace openstudio | ||
| 99 | |||
| 100 | #endif //UTILITIES_FILETYPES_CSVFILE_IMPL_HPP | ||
| 101 |