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;
156 for (
size_t index = row.getValuesCount();
158 row.append(columns_[index]->default_value_);
183 const std::string& reason) {
184 std::ostringstream s;
185 s <<
"Invalid number of columns: "
186 << row.getValuesCount() <<
" in row: '" << row
187 <<
"', file: '" <<
getFilename() <<
"' : " << reason;
195 "cannot validate header, no schema has been defined");
198 input_header_count_ = header.getValuesCount();
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";
int version()
returns Kea hooks version.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Provides input/output access to CSV files.
std::string getColumnName(const size_t col_index) const
Returns the name of the column.
size_t getColumnCount() const
Returns the number of columns in the file.
static CSVRow EMPTY_ROW()
Represents empty row.
void setReadMsg(const std::string &read_msg)
Sets error message after row validation.
std::string getFilename() const
Returns the path to the CSV file.
virtual void recreate()
Creates a new CSV file.
void addColumn(const std::string &col_name)
Adds new column name.
size_t getColumnIndex(const std::string &col_name) const
Returns the index of the column having specified name.
virtual void open(const bool seek_to_end=false)
Opens existing file or creates a new one.
bool next(CSVRow &row, const bool skip_validation=false)
Reads next row from CSV file.
Represents a single row of the CSV file.
Exception thrown when an error occurs during CSV file processing.
bool needsConversion() const
Returns true if the input file schema state is not CURRENT.
virtual void open(const bool seek_to_end=false)
Opens existing file or creates a new one.
virtual ~VersionedCSVFile()
Destructor.
const VersionedColumnPtr & getVersionedColumn(const size_t index) const
Fetch the column descriptor for a given index.
std::string getSchemaVersion() const
text version of current schema supported by the file's metadata
InputSchemaState
Possible input file schema states.
size_t getInputHeaderCount() const
Returns the number of columns found in the input header.
virtual bool validateHeader(const CSVRow &header)
Validates the header of a VersionedCSVFile.
VersionedCSVFile(const std::string &filename)
Constructor.
std::string getInputSchemaVersion() const
Returns the schema version of the physical file.
virtual void recreate()
Creates a new CSV file.
void setMinimumValidColumns(const std::string &column_name)
Sets the minimum number of valid columns based on a given column.
bool next(CSVRow &row)
Reads next row from the file file.
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.
size_t getMinimumValidColumns() const
Returns the minimum number of columns which must be present for the file to be considered valid.
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...
enum InputSchemaState getInputSchemaState() const
Fetches the state of the input file's schema.
Contains the metadata for a single column in a file.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< VersionedColumn > VersionedColumnPtr
Defines a smart pointer to VersionedColumn.
Defines the logger used by the top-level component of kea-lfc.