Clean-up
This commit is contained in:
@@ -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