Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes

CSVImport Class Reference

#include <csvimport.h>

Collaboration diagram for CSVImport:
Collaboration graph
[legend]

List of all members.

Classes

struct  LogEntry

Public Member Functions

 CSVImport (std::string src, std::string dst, char sep, bool verb=true) throw (std::runtime_error)
std::list< LogEntrygetLog () const
 Return the log entries.
bool getVerbose () const
 Get the verbosity.
bool hadErrors () const
 Return whether or not errors occurred.
void import (const char *pw) throw (std::exception)
 Do the import.
unsigned int numErrors () const
 Return the number of errors occurred.
void printLog () const
 Print the log to stdout.
void setVerbose (bool v)
 Set the verbosity.
 ~CSVImport ()

Private Types

enum  { NUM_SEPARATORS = 4 }

Private Member Functions

void cleanupValue (std::string &str)
 Cleanup the field values.
 CSVImport (const CSVImport &)
void logError (unsigned long lno, const std::string &errmsg)
 Log the given error.
const CSVImportoperator= (const CSVImport &)

Private Attributes

std::string dstfile
bool had_errors
std::list< LogEntrylogs
unsigned int num_errors
char separator
std::string srcfile
bool verbose

Detailed Description

The class taking care of converting a csv file.

Definition at line 46 of file csvimport.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
NUM_SEPARATORS 

The expected number of separators.

Definition at line 74 of file csvimport.h.


Constructor & Destructor Documentation

CSVImport::CSVImport ( const CSVImport  )  [inline, private]

Object copying not allowed.

Definition at line 72 of file csvimport.h.

CSVImport::CSVImport ( std::string  src,
std::string  dst,
char  sep,
bool  verb = true 
) throw (std::runtime_error)

The constructor tests whether the given source file exists and can be read. May return a std::runtime_error if this is not the case

Parameters:
src the file path of the source file.
dst the file path of the destination file.
sep the separator used for fields.
verb enable/disable verbosity. Default true.

Definition at line 121 of file csvimport.cc.

CSVImport::~CSVImport (  )  [inline]

Definition at line 119 of file csvimport.h.


Member Function Documentation

void CSVImport::cleanupValue ( std::string &  str  )  [private]

Removes the double quotes at the beginning and any escaped double quotes.

Parameters:
str the string to be cleaned up.
Returns:
the string str passed will be modified.

Definition at line 67 of file csvimport.cc.

std::list<LogEntry> CSVImport::getLog (  )  const [inline]

Definition at line 139 of file csvimport.h.

References logs.

bool CSVImport::getVerbose (  )  const [inline]

Definition at line 127 of file csvimport.h.

References verbose.

bool CSVImport::hadErrors (  )  const [inline]

Definition at line 131 of file csvimport.h.

References had_errors.

Referenced by main().

Here is the caller graph for this function:

void CSVImport::import ( const char *  pw  )  throw (std::exception)

Does the import.

Parameters:
pw the password set on the destination file.

Definition at line 138 of file csvimport.cc.

References clear(), YAPET::PasswordRecord::comment, YAPET::COMMENT_SIZE, YAPET::PasswordRecord::host, YAPET::HOST_SIZE, YAPET::PasswordRecord::name, YAPET::NAME_SIZE, YAPET::PasswordRecord::password, YAPET::PASSWORD_SIZE, YAPET::File::save(), YAPET::PasswordRecord::username, and YAPET::USERNAME_SIZE.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void CSVImport::logError ( unsigned long  lno,
const std::string &  errmsg 
) [private]

Logs the given error.

Parameters:
lno the line number the error occurred.
errmsg the error message.

Definition at line 94 of file csvimport.cc.

References had_errors, CSVImport::LogEntry::lineno, logs, CSVImport::LogEntry::message, num_errors, and verbose.

unsigned int CSVImport::numErrors (  )  const [inline]

Definition at line 135 of file csvimport.h.

References num_errors.

Referenced by main().

Here is the caller graph for this function:

const CSVImport& CSVImport::operator= ( const CSVImport  )  [inline, private]

Object assignment not allowed.

Definition at line 66 of file csvimport.h.

void CSVImport::printLog (  )  const

Prints the log entries to stdout.

Definition at line 260 of file csvimport.cc.

References logs.

Referenced by main().

Here is the caller graph for this function:

void CSVImport::setVerbose ( bool  v  )  [inline]

Definition at line 123 of file csvimport.h.

References verbose.


Member Data Documentation

std::string CSVImport::dstfile [private]

The file path of the destination (pet) file.

Definition at line 88 of file csvimport.h.

bool CSVImport::had_errors [private]

Indicates the occurrence of errors.

Definition at line 101 of file csvimport.h.

Referenced by hadErrors(), and logError().

std::list<LogEntry> CSVImport::logs [private]

Holds the log entries in case of errors.

Definition at line 110 of file csvimport.h.

Referenced by getLog(), logError(), and printLog().

unsigned int CSVImport::num_errors [private]

The number of errors occurred.

Definition at line 105 of file csvimport.h.

Referenced by logError(), and numErrors().

char CSVImport::separator [private]

The separator character.

Definition at line 92 of file csvimport.h.

std::string CSVImport::srcfile [private]

The file path of the source (csv) file.

Definition at line 84 of file csvimport.h.

bool CSVImport::verbose [private]

Verbosity enabled/disabled.

Definition at line 97 of file csvimport.h.

Referenced by getVerbose(), logError(), and setVerbose().


The documentation for this class was generated from the following files: