Clean-up
This commit is contained in:
@@ -184,7 +184,7 @@ namespace ZRCola {
|
||||
///
|
||||
struct character {
|
||||
public:
|
||||
chrcatid_t cat; ///> Category ID
|
||||
chrcatid_t cat; ///> Character category ID
|
||||
|
||||
protected:
|
||||
unsigned __int16 chr_to; ///< Character end in \c data
|
||||
@@ -249,7 +249,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// Character index
|
||||
///
|
||||
class indexChar : public index<unsigned __int16, unsigned __int32, character>
|
||||
class indexChr : public index<unsigned __int16, unsigned __int32, character>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -257,7 +257,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexChar(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, character>(h) {}
|
||||
indexChr(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, character>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two characters by ID (for searching)
|
||||
@@ -327,7 +327,7 @@ namespace ZRCola {
|
||||
assert(len <= 0xffff);
|
||||
std::unique_ptr<character> c((character*)new char[sizeof(character) + sizeof(wchar_t)*len]);
|
||||
c->character::character(chr, len);
|
||||
indexChar::size_type start;
|
||||
indexChr::size_type start;
|
||||
return idxChr.find(*c, start) ? idxChr[start].cat : chrcatid_t::blank;
|
||||
}
|
||||
};
|
||||
@@ -348,7 +348,7 @@ namespace ZRCola {
|
||||
///
|
||||
struct chrcat {
|
||||
public:
|
||||
chrcatid_t id; ///< Character category ID
|
||||
chrcatid_t cat; ///< Character category ID
|
||||
unsigned __int16 rank; ///< Character category rank
|
||||
|
||||
protected:
|
||||
@@ -363,18 +363,18 @@ namespace ZRCola {
|
||||
///
|
||||
/// Constructs the character category
|
||||
///
|
||||
/// \param[in] id Character category ID
|
||||
/// \param[in] cat Character category ID
|
||||
/// \param[in] rank Character category rank
|
||||
/// \param[in] name Character category name
|
||||
/// \param[in] name_len Number of UTF-16 characters in \p name
|
||||
///
|
||||
inline chrcat(
|
||||
_In_opt_ chrcatid_t id = chrcatid_t::blank,
|
||||
_In_opt_ chrcatid_t cat = chrcatid_t::blank,
|
||||
_In_opt_ unsigned __int16 rank = 0,
|
||||
_In_opt_z_count_(name_len) const wchar_t *name = NULL,
|
||||
_In_opt_ size_t name_len = 0)
|
||||
{
|
||||
this->id = id;
|
||||
this->cat = cat;
|
||||
this->rank = rank;
|
||||
this->name_to = static_cast<unsigned __int16>(name_len);
|
||||
if (name_len) memcpy(this->data, name, sizeof(wchar_t)*name_len);
|
||||
@@ -414,11 +414,12 @@ namespace ZRCola {
|
||||
///
|
||||
virtual int compare(_In_ const chrcat &a, _In_ const chrcat &b) const
|
||||
{
|
||||
if (a.id < b.id) return -1;
|
||||
else if (a.id > b.id) return 1;
|
||||
else return 0;
|
||||
if (a.cat < b.cat) return -1;
|
||||
else if (a.cat > b.cat) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxChrCat; ///< Character category index
|
||||
} idxChrCat; ///< Character category index
|
||||
|
||||
///
|
||||
/// Rank index
|
||||
@@ -478,7 +479,7 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxRnk; ///< Rank index
|
||||
} idxRank; ///< Rank index
|
||||
|
||||
std::vector<unsigned __int16> data; ///< Character category data
|
||||
|
||||
@@ -486,7 +487,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// Constructs the database
|
||||
///
|
||||
inline chrcat_db() : idxChrCat(data), idxRnk(data) {}
|
||||
inline chrcat_db() : idxChrCat(data), idxRank(data) {}
|
||||
|
||||
///
|
||||
/// Clears the database
|
||||
@@ -494,7 +495,7 @@ namespace ZRCola {
|
||||
inline void clear()
|
||||
{
|
||||
idxChrCat.clear();
|
||||
idxRnk .clear();
|
||||
idxRank .clear();
|
||||
data .clear();
|
||||
}
|
||||
};
|
||||
@@ -605,7 +606,7 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::c
|
||||
|
||||
// Write rank index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxRnk;
|
||||
stream << db.idxRank;
|
||||
|
||||
// Write data count.
|
||||
auto data_count = db.data.size();
|
||||
@@ -643,7 +644,7 @@ inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::chrcat
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read rank index.
|
||||
stream >> db.idxRnk;
|
||||
stream >> db.idxRank;
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
|
@@ -85,7 +85,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// Character index
|
||||
///
|
||||
class indexChar : public index<unsigned __int16, unsigned __int32, langchar>
|
||||
class indexChr : public index<unsigned __int16, unsigned __int32, langchar>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -93,7 +93,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexChar(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, langchar>(h) {}
|
||||
indexChr(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, langchar>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two characters by ID (for searching)
|
||||
@@ -121,9 +121,9 @@ namespace ZRCola {
|
||||
|
||||
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
|
||||
///
|
||||
/// Character Language Index
|
||||
/// Language Index
|
||||
///
|
||||
class indexCharLang : public index<unsigned __int16, unsigned __int32, langchar>
|
||||
class indexLang : public index<unsigned __int16, unsigned __int32, langchar>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -131,7 +131,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexCharLang(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, langchar>(h) {}
|
||||
indexLang(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, langchar>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two languages by ID (for searching)
|
||||
@@ -154,7 +154,7 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxLng; ///< Character language index
|
||||
} idxLang; ///< Language index
|
||||
#endif
|
||||
|
||||
std::vector<unsigned __int16> data; ///< Character data
|
||||
@@ -165,7 +165,7 @@ namespace ZRCola {
|
||||
///
|
||||
inline langchar_db() : idxChr(data)
|
||||
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
|
||||
, idxLng(data)
|
||||
, idxLang(data)
|
||||
#endif
|
||||
{}
|
||||
|
||||
@@ -174,11 +174,11 @@ namespace ZRCola {
|
||||
///
|
||||
inline void clear()
|
||||
{
|
||||
idxChr.clear();
|
||||
idxChr .clear();
|
||||
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
|
||||
idxLng.clear();
|
||||
idxLang.clear();
|
||||
#endif
|
||||
data .clear();
|
||||
data .clear();
|
||||
}
|
||||
|
||||
///
|
||||
@@ -210,7 +210,7 @@ namespace ZRCola {
|
||||
///
|
||||
struct language {
|
||||
public:
|
||||
langid_t id; ///< Language ID
|
||||
langid_t lang; ///< Language ID
|
||||
|
||||
protected:
|
||||
unsigned __int16 name_to; ///< Language name end in \c data
|
||||
@@ -224,16 +224,16 @@ namespace ZRCola {
|
||||
///
|
||||
/// Constructs the language
|
||||
///
|
||||
/// \param[in] id Language ID
|
||||
/// \param[in] lang Language ID
|
||||
/// \param[in] name Language name
|
||||
/// \param[in] name_len Number of UTF-16 characters in \p name
|
||||
///
|
||||
inline language(
|
||||
_In_opt_ langid_t id = langid_t::blank,
|
||||
_In_opt_ langid_t lang = langid_t::blank,
|
||||
_In_opt_z_count_(name_len) const wchar_t *name = NULL,
|
||||
_In_opt_ size_t name_len = 0)
|
||||
{
|
||||
this->id = id;
|
||||
this->lang = lang;
|
||||
this->name_to = static_cast<unsigned __int16>(name_len);
|
||||
if (name_len) memcpy(this->data, name, sizeof(wchar_t)*name_len);
|
||||
}
|
||||
@@ -272,12 +272,12 @@ namespace ZRCola {
|
||||
///
|
||||
virtual int compare(_In_ const language &a, _In_ const language &b) const
|
||||
{
|
||||
if (a.id < b.id) return -1;
|
||||
else if (a.id > b.id) return 1;
|
||||
if (a.lang < b.lang) return -1;
|
||||
else if (a.lang > b.lang) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxLng; ///< Language index
|
||||
} idxLang; ///< Language index
|
||||
|
||||
std::vector<unsigned __int16> data; ///< Language data
|
||||
|
||||
@@ -285,15 +285,15 @@ namespace ZRCola {
|
||||
///
|
||||
/// Constructs the database
|
||||
///
|
||||
inline language_db() : idxLng(data) {}
|
||||
inline language_db() : idxLang(data) {}
|
||||
|
||||
///
|
||||
/// Clears the database
|
||||
///
|
||||
inline void clear()
|
||||
{
|
||||
idxLng.clear();
|
||||
data .clear();
|
||||
idxLang.clear();
|
||||
data .clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -323,7 +323,7 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::l
|
||||
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
|
||||
// Write language index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxLng;
|
||||
stream << db.idxLang;
|
||||
#endif
|
||||
|
||||
// Write data count.
|
||||
@@ -363,7 +363,7 @@ inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::langch
|
||||
|
||||
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
|
||||
// Read language index.
|
||||
stream >> db.idxLng;
|
||||
stream >> db.idxLang;
|
||||
if (!stream.good()) return stream;
|
||||
#endif
|
||||
|
||||
@@ -395,7 +395,7 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::l
|
||||
{
|
||||
// Write language index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxLng;
|
||||
stream << db.idxLang;
|
||||
|
||||
// Write data count.
|
||||
auto data_count = db.data.size();
|
||||
@@ -429,7 +429,7 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::l
|
||||
inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::language_db &db)
|
||||
{
|
||||
// Read language index.
|
||||
stream >> db.idxLng;
|
||||
stream >> db.idxLang;
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
|
@@ -87,7 +87,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// Character Index
|
||||
///
|
||||
class indexChar : public index<unsigned __int16, unsigned __int32, chrtag>
|
||||
class indexChr : public index<unsigned __int16, unsigned __int32, chrtag>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -95,7 +95,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexChar(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, chrtag>(h) {}
|
||||
indexChr(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, chrtag>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two character tags by character (for searching)
|
||||
|
@@ -123,7 +123,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// Translation index
|
||||
///
|
||||
class indexTrans : public index<unsigned __int16, unsigned __int32, translation>
|
||||
class indexSrc : public index<unsigned __int16, unsigned __int32, translation>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -131,7 +131,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexTrans(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, translation>(h) {}
|
||||
indexSrc(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, translation>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two transformations by string (for searching)
|
||||
@@ -182,13 +182,13 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxTrans; ///< Translation index
|
||||
} idxSrc; ///< Translation index
|
||||
|
||||
|
||||
///
|
||||
/// Inverse translation index
|
||||
///
|
||||
class indexTransInv : public index<unsigned __int16, unsigned __int32, translation>
|
||||
class indexDst : public index<unsigned __int16, unsigned __int32, translation>
|
||||
{
|
||||
public:
|
||||
///
|
||||
@@ -196,7 +196,7 @@ namespace ZRCola {
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexTransInv(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, translation>(h) {}
|
||||
indexDst(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, translation>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two transformations by character (for searching)
|
||||
@@ -247,7 +247,7 @@ namespace ZRCola {
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxTransInv; ///< Inverse translation index
|
||||
} idxDst; ///< Inverse translation index
|
||||
|
||||
|
||||
std::vector<unsigned __int16> data; ///< Transformation data
|
||||
@@ -256,16 +256,16 @@ namespace ZRCola {
|
||||
///
|
||||
/// Constructs the database
|
||||
///
|
||||
inline translation_db() : idxTrans(data), idxTransInv(data) {}
|
||||
inline translation_db() : idxSrc(data), idxDst(data) {}
|
||||
|
||||
///
|
||||
/// Clears the database
|
||||
///
|
||||
inline void clear()
|
||||
{
|
||||
idxTrans .clear();
|
||||
idxTransInv.clear();
|
||||
data .clear();
|
||||
idxSrc.clear();
|
||||
idxDst.clear();
|
||||
data .clear();
|
||||
}
|
||||
|
||||
///
|
||||
@@ -309,10 +309,114 @@ namespace ZRCola {
|
||||
|
||||
|
||||
typedef ZRCOLA_API stdex::idrec::record<translation_db, recordid_t, recordsize_t, ZRCOLA_RECORD_ALIGN> translation_rec;
|
||||
|
||||
|
||||
///
|
||||
/// Translation set database
|
||||
///
|
||||
class ZRCOLA_API transet_db {
|
||||
public:
|
||||
#pragma pack(push)
|
||||
#pragma pack(2)
|
||||
///
|
||||
/// Translation set data
|
||||
///
|
||||
struct transet {
|
||||
public:
|
||||
transetid_t set; ///< Translation set ID
|
||||
|
||||
protected:
|
||||
unsigned __int16 name_to; ///< Translation set name end in \c data
|
||||
wchar_t data[]; ///< Translation set name
|
||||
|
||||
private:
|
||||
inline transet(_In_ const transet &other);
|
||||
inline transet& operator=(_In_ const transet &other);
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the translation set
|
||||
///
|
||||
/// \param[in] set Translation set ID
|
||||
/// \param[in] name Translation set name
|
||||
/// \param[in] name_len Number of UTF-16 characters in \p name
|
||||
///
|
||||
inline transet(
|
||||
_In_opt_ transetid_t set = 0,
|
||||
_In_opt_z_count_(name_len) const wchar_t *name = NULL,
|
||||
_In_opt_ size_t name_len = 0)
|
||||
{
|
||||
this->set = set;
|
||||
this->name_to = static_cast<unsigned __int16>(name_len);
|
||||
if (name_len) memcpy(this->data, name, sizeof(wchar_t)*name_len);
|
||||
}
|
||||
|
||||
inline const wchar_t* name () const { return data; };
|
||||
inline wchar_t* name () { return data; };
|
||||
inline const wchar_t* name_end() const { return data + name_to; };
|
||||
inline wchar_t* name_end() { return data + name_to; };
|
||||
inline unsigned __int16 name_len() const { return name_to; };
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
///
|
||||
/// Translation set index
|
||||
///
|
||||
class indexTranSet : public index<unsigned __int16, unsigned __int32, transet>
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs the index
|
||||
///
|
||||
/// \param[in] h Reference to vector holding the data
|
||||
///
|
||||
indexTranSet(_In_ std::vector<unsigned __int16> &h) : index<unsigned __int16, unsigned __int32, transet>(h) {}
|
||||
|
||||
///
|
||||
/// Compares two translation sets by ID (for searching)
|
||||
///
|
||||
/// \param[in] a Pointer to first element
|
||||
/// \param[in] b Pointer to second element
|
||||
///
|
||||
/// \returns
|
||||
/// - <0 when a < b
|
||||
/// - =0 when a == b
|
||||
/// - >0 when a > b
|
||||
///
|
||||
virtual int compare(_In_ const transet &a, _In_ const transet &b) const
|
||||
{
|
||||
if (a.set < b.set) return -1;
|
||||
else if (a.set > b.set) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
} idxTranSet; ///< Translation set index
|
||||
|
||||
std::vector<unsigned __int16> data; ///< Translation set data
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the database
|
||||
///
|
||||
inline transet_db() : idxTranSet(data) {}
|
||||
|
||||
///
|
||||
/// Clears the database
|
||||
///
|
||||
inline void clear()
|
||||
{
|
||||
idxTranSet.clear();
|
||||
data .clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef ZRCOLA_API stdex::idrec::record<transet_db, recordid_t, recordsize_t, ZRCOLA_RECORD_ALIGN> transet_rec;
|
||||
};
|
||||
|
||||
|
||||
const ZRCola::recordid_t ZRCola::translation_rec::id = *(ZRCola::recordid_t*)"TRN";
|
||||
const ZRCola::recordid_t ZRCola::transet_rec ::id = *(ZRCola::recordid_t*)"TSE";
|
||||
|
||||
|
||||
///
|
||||
@@ -327,11 +431,11 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::t
|
||||
{
|
||||
// Write translation index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxTrans;
|
||||
stream << db.idxSrc;
|
||||
|
||||
// Write inverse translation index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxTransInv;
|
||||
stream << db.idxDst;
|
||||
|
||||
// Write data count.
|
||||
auto data_count = db.data.size();
|
||||
@@ -365,11 +469,76 @@ inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::t
|
||||
inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::translation_db &db)
|
||||
{
|
||||
// Read translation index.
|
||||
stream >> db.idxTrans;
|
||||
stream >> db.idxSrc;
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read inverse translation index.
|
||||
stream >> db.idxTransInv;
|
||||
stream >> db.idxDst;
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
unsigned __int32 count;
|
||||
stream.read((char*)&count, sizeof(count));
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
if (count) {
|
||||
// Read data.
|
||||
db.data.resize(count);
|
||||
stream.read((char*)db.data.data(), sizeof(unsigned __int16)*count);
|
||||
} else
|
||||
db.data.clear();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Writes translation set database to a stream
|
||||
///
|
||||
/// \param[in] stream Output stream
|
||||
/// \param[in] db Translation set database
|
||||
///
|
||||
/// \returns The stream \p stream
|
||||
///
|
||||
inline std::ostream& operator <<(_In_ std::ostream& stream, _In_ const ZRCola::transet_db &db)
|
||||
{
|
||||
// Write translation set index.
|
||||
if (stream.fail()) return stream;
|
||||
stream << db.idxTranSet;
|
||||
|
||||
// Write data count.
|
||||
auto data_count = db.data.size();
|
||||
#if defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__)
|
||||
// 4G check
|
||||
if (data_count > 0xffffffff) {
|
||||
stream.setstate(std::ios_base::failbit);
|
||||
return stream;
|
||||
}
|
||||
#endif
|
||||
if (stream.fail()) return stream;
|
||||
unsigned __int32 count = (unsigned __int32)data_count;
|
||||
stream.write((const char*)&count, sizeof(count));
|
||||
|
||||
// Write data.
|
||||
if (stream.fail()) return stream;
|
||||
stream.write((const char*)db.data.data(), sizeof(unsigned __int16)*count);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Reads translation set database from a stream
|
||||
///
|
||||
/// \param[in ] stream Input stream
|
||||
/// \param[out] db Translation set database
|
||||
///
|
||||
/// \returns The stream \p stream
|
||||
///
|
||||
inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::transet_db &db)
|
||||
{
|
||||
// Read translation set index.
|
||||
stream >> db.idxTranSet;
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
|
Reference in New Issue
Block a user