15 :
CSVFile(filename), columns_(0), valid_column_count_(0),
16 minimum_valid_columns_(0), input_header_count_(0),
17 input_schema_state_(CURRENT) {
26 const std::string& default_value) {
36 minimum_valid_columns_ = index + 1;
40 "setMinimumValidColumns: " << column_name <<
" is not " 47 return (minimum_valid_columns_);
52 return (valid_column_count_);
57 return (input_header_count_);
64 "no schema has been defined, cannot open CSV file :" 75 "no schema has been defined, cannot create CSV file :" 86 return (input_schema_state_);
91 return (input_schema_state_ !=
CURRENT);
100 return (
"undefined");
109 return (
"undefined");
120 return (columns_[index]);
133 bool row_valid =
true;
158 row.
append(columns_[index]->default_value_);
183 const std::string& reason) {
184 std::ostringstream s;
185 s <<
"Invalid number of columns: " 187 <<
"', file: '" <<
getFilename() <<
"' : " << reason;
195 "cannot validate header, no schema has been defined");
206 std::ostringstream s;
207 s <<
" - header contains an invalid column: '" 208 << header.
readAt(i) <<
"'";
217 std::ostringstream s;
218 s <<
" - header has only " << i <<
" valid column(s), " 228 valid_column_count_ = i;
237 std::ostringstream s;
239 <<
" extra column(s), these will be ignored";
size_t getMinimumValidColumns() const
Returns the minimum number of columns which must be present for the file to be considered valid...
virtual ~VersionedCSVFile()
Destructor.
virtual void recreate()
Creates a new CSV file.
size_t getColumnCount() const
Returns the number of columns in the file.
size_t getInputHeaderCount() const
Returns the number of columns found in the input header.
static CSVRow EMPTY_ROW()
Represents empty row.
InputSchemaState
Possible input file schema states.
std::string getFilename() const
Returns the path to the CSV file.
void trim(const size_t count)
Trims a given number of elements from the end of a row.
Contains the metadata for a single column in a file.
std::string getSchemaVersion() const
text version of current schema supported by the file's metadata
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual void open(const bool seek_to_end=false)
Opens existing file or creates a new one.
virtual bool validateHeader(const CSVRow &header)
Validates the header of a VersionedCSVFile.
virtual void recreate()
Creates a new CSV file.
size_t getValuesCount() const
Returns number of values in a CSV row.
boost::shared_ptr< VersionedColumn > VersionedColumnPtr
Defines a smart pointer to VersionedColumn.
void setMinimumValidColumns(const std::string &column_name)
Sets the minimum number of valid columns based on a given column.
int version()
returns Kea hooks version.
Represents a single row of the CSV file.
Exception thrown when an error occurs during CSV file processing.
void setReadMsg(const std::string &read_msg)
Sets error message after row validation.
std::string getInputSchemaVersion() const
Returns the schema version of the physical file.
bool needsConversion() const
Returns true if the input file schema state is not CURRENT.
Defines the logger used by the top-level component of kea-lfc.
void addColumn(const std::string &col_name, const std::string &version, const std::string &default_value="")
Adds metadata for a single column to the schema.
void addColumn(const std::string &col_name)
Adds new column name.
bool next(CSVRow &row)
Reads next row from the file file.
std::string getColumnName(const size_t col_index) const
Returns the name of the column.
enum InputSchemaState getInputSchemaState() const
Fetches the state of the input file's schema.
size_t getColumnIndex(const std::string &col_name) const
Returns the index of the column having specified name.
std::string readAt(const size_t at) const
Retrieves a value from the internal container.
Provides input/output access to CSV files.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
bool next(CSVRow &row, const bool skip_validation=false)
Reads next row from CSV file.
void columnCountError(const CSVRow &row, const std::string &reason)
Convenience method for adding an error message.
size_t getValidColumnCount() const
Returns the number of valid columns found in the header For newly created files this will always matc...
VersionedCSVFile(const std::string &filename)
Constructor.
void append(const T value)
Appends the value as a new column.
const VersionedColumnPtr & getVersionedColumn(const size_t index) const
Fetch the column descriptor for a given index.
virtual void open(const bool seek_to_end=false)
Opens existing file or creates a new one.