Main Page   Namespaces   Classes ( Hierarchy )   Functions & Members  

moFileLib::moFileReader Class Reference

This class is a gettext-replacement. More...

#include <moFileReader.h>

Inheritance diagram for moFileLib::moFileReader:

Inheritance graph
[legend]
Collaboration diagram for moFileLib::moFileReader:

Collaboration graph
[legend]

List of all members.

Public Types

enum  eErrorCode {
  EC_SUCCESS = 0, EC_ERROR, EC_FILENOTFOUND, EC_FILEINVALID,
  EC_TABLEEMPTY, EC_MAGICNUMBER_NOMATCH, EC_MAGICNUMBER_REVERSED
}
 The possible errorcodes for methods of this class. More...

Public Member Functions

virtual eErrorCode ReadFile (const char *_filename)
 Reads a .mo-file.
virtual std::string Lookup (const char *_id) const
 Returns the searched translation or returns the input.
virtual const std::string & GetErrorDescription () const
 Returns the Error Description.
virtual void ClearTable ()
 Empties the Lookup-Table.
virtual unsigned int GetNumStrings () const
 Returns the Number of Entries in our Lookup-Table.

Static Public Member Functions

static eErrorCode ExportAsHTML (const std::string _infile, const std::string _filename="", const std::string _css=g_css)
 Exports the whole content of the .mo-File as .html.

Static Public Attributes

static const long _MagicNumber = 0x950412DE
 The Magic Number describes the endianess of bytes on the system.
static const long _MagicReversed = 0xDE120495
 If the Magic Number is Reversed, we need to swap the bytes.

Protected Types

typedef std::map< std::string,
std::string > 
moLookupList
 Type for the map which holds the translation-pairs later.

Protected Member Functions

unsigned long SwapBytes (unsigned long _in)
 Swap the endianness of a 4 byte WORD.

Protected Attributes

std::string m_error
 Keeps the last error as String.


Detailed Description

This class is a gettext-replacement.

The usage is quite simple:
Tell the class which .mo-file it shall load via moFileReader::ReadFile(). The method will attempt to load the file, all translations will be stored in memory. Afterwards you can lookup the strings with moFileReader::Lookup() just like you would do with gettext. Additionally, you can call moFileReader::ReadFile() for as much files as you like. But please be aware, that if there are duplicated keys (original strings), that they will replace each other in the lookup-table. There is no check done, if a key already exists.

Note:
If you add "Lookup" to the keywords of the gettext-parser (like poEdit), it will recognize the Strings loaded with an instance of this class.

I strongly recommend poEdit from Vaclav Slavik for editing .po-Files, get it at http://poedit.net for various systems :).


Member Typedef Documentation

typedef std::map<std::string, std::string> moFileLib::moFileReader::moLookupList [protected]

Type for the map which holds the translation-pairs later.


Member Enumeration Documentation

The possible errorcodes for methods of this class.

Enumerator:
EC_SUCCESS  Indicated success.
EC_ERROR  Indicates an error.
EC_FILENOTFOUND  The given File was not found.
EC_FILEINVALID  The file is invalid.
EC_TABLEEMPTY  Empty Lookup-Table (returned by ExportAsHTML()).
EC_MAGICNUMBER_NOMATCH  The magic number did not match.
EC_MAGICNUMBER_REVERSED  The magic number is reversed.

Note:
This is an error until the class supports it.


Member Function Documentation

virtual void moFileLib::moFileReader::ClearTable (  )  [virtual]

Empties the Lookup-Table.

static eErrorCode moFileLib::moFileReader::ExportAsHTML ( const std::string  _infile,
const std::string  _filename = "",
const std::string  _css = g_css 
) [static]

Exports the whole content of the .mo-File as .html.

Parameters:
[in] _infile The .mo-File to export.
[in] _filename Where to store the .html-file. If empty, the path and filename of the _infile with .html appended.
[in,out] _css The css-script for the visual style of the file, in case you don't like mine ;).
See also:
g_css for the possible and used css-values.

virtual const std::string& moFileLib::moFileReader::GetErrorDescription (  )  const [virtual]

Returns the Error Description.

virtual unsigned int moFileLib::moFileReader::GetNumStrings (  )  const [virtual]

Returns the Number of Entries in our Lookup-Table.

Note:
The mo-File-table always contains an empty msgid, which contains informations about the tranlsation-project. So the real number of strings is always minus 1.

virtual std::string moFileLib::moFileReader::Lookup ( const char *  _id  )  const [virtual]

Returns the searched translation or returns the input.

Parameters:
[in,out] _id The id of the translation to search for.
Returns:
The value you passed in via _id or the translated string.

virtual eErrorCode moFileLib::moFileReader::ReadFile ( const char *  _filename  )  [virtual]

Reads a .mo-file.

Parameters:
[in] _filename The path to the file to load.
Returns:
SUCCESS on success or one of the other error-codes in eErrorCode on error.
This is the core-feature. This method loads the .mo-file and stores all translation-pairs in a map. You can access this map via the method moFileReader::Lookup().

unsigned long moFileLib::moFileReader::SwapBytes ( unsigned long  _in  )  [protected]

Swap the endianness of a 4 byte WORD.

Parameters:
[in] _in The value to swap.
Returns:
The swapped value.


Member Data Documentation

const long moFileLib::moFileReader::_MagicNumber = 0x950412DE [static]

The Magic Number describes the endianess of bytes on the system.

const long moFileLib::moFileReader::_MagicReversed = 0xDE120495 [static]

If the Magic Number is Reversed, we need to swap the bytes.

std::string moFileLib::moFileReader::m_error [protected]

Keeps the last error as String.


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

Generated on 17 Jan 2009 for moFileReader by Doxygen1.5.7.1