sella::file::GZCSVPathReader Class Reference

#include <GZCSVPathReader.h>

List of all members.

Public Member Functions

 STANDARD_TYPEDEF (sella::file::GZCSVPathReader)
 GZCSVPathReader (const std::string &path, char delimiter=DefaultDelimiter, char seperator=DefaultSeperator) THROWS(IOException)
void read (std::vector< std::vector< std::string >> &data) THROWS(IOException)

Static Public Attributes

static const char * FileSuffix = ".csv.gz"
 The file suffix for matching files in the directory for reading.
static const char DefaultDelimiter = 0x1e
 The default delimiter used between the fields of a record; the ASCII record seperator character.
static const char DefaultSeperator = 0x1d
 The default seperator used between the records of a file; the ASCII group seperator character.

Static Protected Member Functions

static int filter (const struct dirent *file) NO_EXCEPTIONS

Detailed Description

A GZIP compressed CSV path reader class.

Definition at line 34 of file GZCSVPathReader.h.


Constructor & Destructor Documentation

GZCSVPathReader::GZCSVPathReader ( const std::string &  path,
char  delimiter = DefaultDelimiter,
char  seperator = DefaultSeperator 
)

The base constructor for a path reader.

Parameters:
[in] path The full path to write files to.
[in] delimiter The field delimiter character for files.
[in] seperator The record seperator character for files.
Exceptions:
IOException if the path cannot be opened for reading.

Definition at line 29 of file GZCSVPathReader.cpp.

00029                                                                                                            :
00030         path(path),
00031 
00032         delimiter(delimiter),
00033         seperator(seperator)
00034 {
00035         /* Ensure the supplied path is valid. */
00036         DIR * directory = ::opendir(this->path.c_str());
00037 
00038         if (directory == NULL) {
00039                 THROW(IOException, "failed to open directory '%s' for reading", this->path.c_str());
00040         }
00041         ::closedir(directory);
00042 
00043         /* Remove any trailing slash characters from the path. */
00044         while (*(this->path.rbegin()) == '/') {
00045                 this->path.erase(this->path.length() - 1, 1);
00046         }
00047 }


Member Function Documentation

int GZCSVPathReader::filter ( const struct dirent *  file  )  [static, protected]

Filter files from the path based on their name.

Parameters:
[in] file The direct structure for a single file.
Returns:
1 if the file matches the desired patter, or 0 if it does not.

Definition at line 91 of file GZCSVPathReader.cpp.

References FileSuffix.

Referenced by read().

00091                                                                     {
00092         static size_t base = ::strlen(GZCSVPathReader::FileSuffix);
00093         size_t        size = ::strlen(file->d_name);
00094         
00095         if ((size >= base) && (::strncmp(&(file->d_name[size - base]), GZCSVPathReader::FileSuffix, base) == 0)) {
00096                 return 1;
00097         }
00098         return 0;
00099 }

void GZCSVPathReader::read ( std::vector< std::vector< std::string >> &  data  ) 

Read all files in the path defined for this instance.

Parameters:
[in] data The vector to which all data will be written; if not empty this function will clear the vector before writing data.
Exceptions:
IOException if unabled to read the directory for any reason.

Definition at line 57 of file GZCSVPathReader.cpp.

References sella::file::GZCSVFileReader::close(), filter(), and sella::file::GZCSVFileReader::read().

00057                                                                                      {
00058         struct dirent ** file;
00059         int              n;
00060 
00061         /* Clear the result set before reading. */
00062         if (data.empty() == false) {
00063                 data.clear();
00064         }
00065 
00066         /* Read all record entries from all files. */
00067         if ((n = ::scandir(this->path.c_str(), &file, GZCSVPathReader::filter, ::alphasort)) >= 0) {
00068                 for (int i = 0; i < n; i++) {
00069                         try {
00070                                 GZCSVFileReader reader(std::string(this->path).append("/").append(file[i]->d_name), this->delimiter, this->seperator);
00071 
00072                                 reader.read(data);
00073                                 reader.close();
00074                         } catch (IOException & e) { /* IGNORE */ }
00075 
00076                         ::free(file[i]);
00077                 }
00078                 ::free(file);
00079         } else {
00080                 THROW(IOException, "failed to open directory '%s' for reading", this->path.c_str());
00081         }
00082 }


The documentation for this class was generated from the following files:
 All Classes Functions Variables

Generated on 20 Nov 2014 for libutil++ by  doxygen 1.6.1