XMLParser Class Reference

XML file parsing class. More...

#include <xmlparser.h>

Collaboration diagram for XMLParser:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 XMLParser ()
 Default constructor.
void Init (const std::string &file_path)
Card card (unsigned index, unsigned grade_min=0, unsigned grade_max=0, unsigned strokes_min=0, unsigned strokes_max=0)
 Get a card determined by its index.
int package_records () const
 Get the number of records in the package.
int QueryResultSize (unsigned grade_min, unsigned grade_max, unsigned strokes_min, unsigned strokes_max)
 Get the number of kanjis with the given grade and strokes restriction.

Private Types

enum  mode { XML_KANJI, XML_VOCABULARY }
 XML format types.

Private Member Functions

bool compare (const char *s1, const char *s2)
 Simple equality string comparing function.
bool find (const char *s, const char *buffer, int &position)
 Simple finding function.
void GenerateIndexes ()
 Fill the indexes file_cursor_ , grade_ and strokes_.
unsigned GetIndex (unsigned index, unsigned grade_min, unsigned grade_max, unsigned strokes_min, unsigned strokes_max)
void QueryResult (unsigned grade_min, unsigned grade_max, unsigned strokes_min, unsigned strokes_max)
 Generate the result vector for the given grades and strokes ranges.
std::string attribute_value (const char *name, const char *buffer, int &position)

Private Attributes

FILE * file_
 XML file.
std::string file_path_
 File path.
std::string xml_version_
 XML file version.
std::string package_name_
 Name of the package in the file (only one package per file is supported).
int package_records_
 Number of cards in the package.
std::string package_format_
 Format of the package.
std::string package_license_
 License of the package.
mode file_format_
 File format.
fpos_t * file_cursor_
 File cards positions vector.
std::vector< int > * grade_
 Vector of cards numbers organized by grade.
std::vector< int > * strokes_
 Vector of cards numbers organized by strokes.
std::vector< int > query_result_
unsigned q_grade_min_
 Minimum grade of the actual query.
unsigned q_grade_max_
 Maximum grade of the actual query.
unsigned q_strokes_min_
 Minimum strokes of the actual query.
unsigned q_strokes_max_
 Maximum strokes of the actual query.

Static Private Attributes

static const int BUFFER_SIZE = 512
 Temporal reading buffer size.


Detailed Description

XML file parsing class.

Definition at line 27 of file xmlparser.h.


Member Function Documentation

string XMLParser::attribute_value ( const char *  name,
const char *  buffer,
int &  position 
) [private]

Gives the value of an attribute in a XML formatted line

Parameters:
name Name of the attribute
buffer XML line to search in
position Position to start searching. It's updated to the last read character position

Definition at line 147 of file xmlparser.cpp.

Referenced by card(), GenerateIndexes(), and Init().

unsigned XMLParser::GetIndex ( unsigned  index,
unsigned  grade_min,
unsigned  grade_max,
unsigned  strokes_min,
unsigned  strokes_max 
) [private]

Gets the package card index acording to the grade and strokes if given.

Parameters:
index Number of the card to retrieve regarding given grade and strokes
grade_min Minimum grade of the kanji to retrieve.
grade_max Maximum grade of the kanji to retrieve.
strokes_min Minimum number of strokes of the kanji to retrieve.
strokes_max Maximum number of strokes of the kanji to retrieve.
Returns:
A number [1 - package_records_] if the kanji could be found.

0 if wasn't found any kanji regarding the parameters.

Definition at line 193 of file xmlparser.cpp.

Referenced by card().

void XMLParser::Init ( const std::string &  file_path  ) 

Initializer

Parameters:
file_path Path of the file to read

Definition at line 46 of file xmlparser.cpp.

Referenced by DSMemorizer::KanjiMode(), DSMemorizer::KanjiQuizMode(), DSMemorizer::VocabularyMode(), and DSMemorizer::VocabularyQuizMode().


Member Data Documentation

std::vector<int> XMLParser::query_result_ [private]

Vector of the results of the query in the database for the selected grades and strokes range

Definition at line 81 of file xmlparser.h.

Referenced by GetIndex(), QueryResult(), and QueryResultSize().


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

Generated on Fri Oct 2 10:25:29 2009 for DSMemorizer by  doxygen 1.5.8