OpenStudio:utilities
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
openstudio::CSVFile Class Reference

#include <CSVFile.hpp>

Public Member Functions

unsigned addColumn (const std::vector< DateTime > &dateTimes)
 Add a column of std::vector<DateTime>, returns column index (first column is index 0). More...
 
unsigned addColumn (const Vector &values)
 Add a column of values in a Vector, returns column index (first column is index 0). More...
 
unsigned addColumn (const std::vector< double > &values)
 Add a column of values in a std::vector<double>, returns column index (first column is index 0). More...
 
unsigned addColumn (const std::vector< std::string > &values)
 Add a column of values in a std::vector<std::string>, returns column index (first column is index 0). More...
 
void addRow (const std::vector< Variant > &row)
 Add a row. More...
 
void clear ()
 Clear all rows. More...
 
CSVFile clone () const
 Clones this CSVFile into a separate one. More...
 
 CSVFile ()
 Create a new, empty CSVFile. More...
 
 CSVFile (const std::string &s)
 Constructor with string, will throw if string is not a CSVFile. More...
 
 CSVFile (const openstudio::path &p)
 Constructor with path, will throw if path does not exist or file is incorrect. More...
 
std::vector< DateTimegetColumnAsDateTimes (unsigned columnIndex) const
 Get column of DateTime values (first column is index 0). More...
 
std::vector< double > getColumnAsDoubleVector (unsigned columnIndex) const
 Get column as a Vector (first column is index 0). More...
 
std::vector< std::string > getColumnAsStringVector (unsigned columnIndex) const
 Get column as a Vector (first column is index 0). More...
 
unsigned numColumns () const
 Returns number of columns, this is the maximum number of columns across all rows. More...
 
unsigned numRows () const
 Returns number of rows. More...
 
boost::optional< openstudio::path > path () const
 Returns the absolute path this CSVFile was loaded from or saved to, empty for new CSVFile. More...
 
void resetPath ()
 Resets the absolute path for this CSVFile. More...
 
std::vector< std::vector
< Variant > > 
rows () const
 Get all rows. More...
 
bool save () const
 Saves this file to the current location, fails if no path is set. More...
 
bool saveAs (const openstudio::path &p)
 Saves this file to a new location. More...
 
bool setPath (const openstudio::path &path)
 Sets the absolute path for this CSVFile. More...
 
void setRows (const std::vector< std::vector< Variant > > &rows)
 Set all rows. More...
 
std::string string () const
 Get the CSVFile as a string. More...
 

Static Public Member Functions

static boost::optional< CSVFileload (const std::string &s)
 Attempt to load a CSVFile from string. More...
 
static boost::optional< CSVFileload (const openstudio::path &p)
 Attempt to load a CSVFile from path. More...
 

Protected Member Functions

 CSVFile (std::shared_ptr< detail::CSVFile_Impl > impl)
 Protected constructor from impl. More...
 

Detailed Description

Class for reading and writing CSV files.

Constructor & Destructor Documentation

openstudio::CSVFile::CSVFile ( )

Create a new, empty CSVFile.

openstudio::CSVFile::CSVFile ( const std::string &  s)

Constructor with string, will throw if string is not a CSVFile.

openstudio::CSVFile::CSVFile ( const openstudio::path &  p)

Constructor with path, will throw if path does not exist or file is incorrect.

openstudio::CSVFile::CSVFile ( std::shared_ptr< detail::CSVFile_Impl >  impl)
protected

Protected constructor from impl.

Member Function Documentation

unsigned openstudio::CSVFile::addColumn ( const std::vector< DateTime > &  dateTimes)

Add a column of std::vector<DateTime>, returns column index (first column is index 0).

unsigned openstudio::CSVFile::addColumn ( const Vector &  values)

Add a column of values in a Vector, returns column index (first column is index 0).

unsigned openstudio::CSVFile::addColumn ( const std::vector< double > &  values)

Add a column of values in a std::vector<double>, returns column index (first column is index 0).

unsigned openstudio::CSVFile::addColumn ( const std::vector< std::string > &  values)

Add a column of values in a std::vector<std::string>, returns column index (first column is index 0).

void openstudio::CSVFile::addRow ( const std::vector< Variant > &  row)

Add a row.

void openstudio::CSVFile::clear ( )

Clear all rows.

CSVFile openstudio::CSVFile::clone ( ) const

Clones this CSVFile into a separate one.

std::vector<DateTime> openstudio::CSVFile::getColumnAsDateTimes ( unsigned  columnIndex) const

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.

std::vector<double> openstudio::CSVFile::getColumnAsDoubleVector ( unsigned  columnIndex) const

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.

std::vector<std::string> openstudio::CSVFile::getColumnAsStringVector ( unsigned  columnIndex) const

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.

static boost::optional<CSVFile> openstudio::CSVFile::load ( const std::string &  s)
static

Attempt to load a CSVFile from string.

static boost::optional<CSVFile> openstudio::CSVFile::load ( const openstudio::path &  p)
static

Attempt to load a CSVFile from path.

unsigned openstudio::CSVFile::numColumns ( ) const

Returns number of columns, this is the maximum number of columns across all rows.

unsigned openstudio::CSVFile::numRows ( ) const

Returns number of rows.

boost::optional<openstudio::path> openstudio::CSVFile::path ( ) const

Returns the absolute path this CSVFile was loaded from or saved to, empty for new CSVFile.

void openstudio::CSVFile::resetPath ( )

Resets the absolute path for this CSVFile.

std::vector<std::vector<Variant> > openstudio::CSVFile::rows ( ) const

Get all rows.

bool openstudio::CSVFile::save ( ) const

Saves this file to the current location, fails if no path is set.

bool openstudio::CSVFile::saveAs ( const openstudio::path &  p)

Saves this file to a new location.

Updates the CSVFile path.

bool openstudio::CSVFile::setPath ( const openstudio::path &  path)

Sets the absolute path for this CSVFile.

void openstudio::CSVFile::setRows ( const std::vector< std::vector< Variant > > &  rows)

Set all rows.

std::string openstudio::CSVFile::string ( ) const

Get the CSVFile as a string.