diff --git a/lib/libZRCola/include/zrcola/common.h b/lib/libZRCola/include/zrcola/common.h index c8304f3..6d73d37 100644 --- a/lib/libZRCola/include/zrcola/common.h +++ b/lib/libZRCola/include/zrcola/common.h @@ -33,6 +33,7 @@ #define ZRCOLA_NOVTABLE __declspec(novtable) #pragma warning(push) #pragma warning(disable: 4251) +#pragma warning(disable: 4512) /// @@ -54,16 +55,26 @@ namespace ZRCola { /// /// Memory index /// - template - class index : public std::vector + template + class index : public std::vector { + protected: + std::vector &host; ///< Reference to host data + public: + /// + /// Constructs the index + /// + /// \param[in] h Reference to vector holding the data + /// + index(_In_ std::vector &h) : host(h) {} + /// /// Sorts index /// inline void sort() { - qsort_s(data(), size(), sizeof(T), compare_s, this); + qsort_s(data(), size(), sizeof(T_idx), compare_s, this); } /// @@ -77,12 +88,13 @@ namespace ZRCola { /// - =0 when a == b /// - >0 when a > b /// - virtual int compare(_In_ const void *a, _In_ const void *b) const = 0; + virtual int compare(_In_ const T &a, _In_ const T &b) const = 0; private: static int __cdecl compare_s(void *p, const void *a, const void *b) { - return ((const index*)p)->compare(a, b); + const index *t = (const index*)p; + return t->compare(t->host[*(const T_idx*)a], t->host[*(const T_idx*)b]); } }; diff --git a/lib/libZRCola/include/zrcola/translate.h b/lib/libZRCola/include/zrcola/translate.h index 8cce97d..997a0fc 100644 --- a/lib/libZRCola/include/zrcola/translate.h +++ b/lib/libZRCola/include/zrcola/translate.h @@ -81,18 +81,15 @@ namespace ZRCola { /// /// Composition index /// - class indexComp : public index + class indexComp : public index { - protected: - std::vector &source; ///< Reference to source data - public: /// /// Constructs the index /// - /// \param[in] d Reference to vector holding the data + /// \param[in] h Reference to vector holding the data /// - indexComp(_In_ std::vector &s) : source(s) {} + indexComp(_In_ std::vector &h) : index(h) {} /// /// Compares two transformations by string @@ -105,11 +102,11 @@ namespace ZRCola { /// - =0 when a == b /// - >0 when a > b /// - virtual int compare(_In_ const void *a, _In_ const void *b) const + virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const { const translation - &trans_a = (const translation&)source[*(const unsigned __int32*)a], - &trans_b = (const translation&)source[*(const unsigned __int32*)b]; + &trans_a = (const translation&)a, + &trans_b = (const translation&)b; int r = translation::CompareString(trans_a.str, trans_a.str_len, trans_b.str, trans_b.str_len); if (r != 0) return r; @@ -125,18 +122,15 @@ namespace ZRCola { /// /// Decomposition index /// - class indexDecomp : public index + class indexDecomp : public index { - protected: - std::vector &source; ///< Reference to source data - public: /// /// Constructs the index /// - /// \param[in] d Reference to vector holding the data + /// \param[in] h Reference to vector holding the data /// - indexDecomp(_In_ std::vector &s) : source(s) {} + indexDecomp(_In_ std::vector &h) : index(h) {} /// /// Compares two transformations by string @@ -149,11 +143,11 @@ namespace ZRCola { /// - =0 when a == b /// - >0 when a > b /// - virtual int compare(_In_ const void *a, _In_ const void *b) const + virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const { const translation - &trans_a = (const translation&)source[*(const unsigned __int32*)a], - &trans_b = (const translation&)source[*(const unsigned __int32*)b]; + &trans_a = (const translation&)a, + &trans_b = (const translation&)b; if (trans_a.chr < trans_b.chr) return -1; else if (trans_a.chr > trans_b.chr) return +1; diff --git a/lib/libZRColaUI/include/zrcolaui/keyboard.h b/lib/libZRColaUI/include/zrcolaui/keyboard.h index 471c9d8..26bc53e 100644 --- a/lib/libZRColaUI/include/zrcolaui/keyboard.h +++ b/lib/libZRColaUI/include/zrcolaui/keyboard.h @@ -89,18 +89,15 @@ namespace ZRCola { /// /// Character index /// - class indexChr : public index + class indexChr : public index { - protected: - std::vector &source; ///< Reference to source data - public: /// /// Constructs the index /// - /// \param[in] d Reference to vector holding the data + /// \param[in] h Reference to vector holding the data /// - indexChr(_In_ std::vector &s) : source(s) {} + indexChr(_In_ std::vector &h) : index(h) {} /// /// Compares two key sequences by character @@ -113,11 +110,11 @@ namespace ZRCola { /// - =0 when a == b /// - >0 when a > b /// - virtual int compare(_In_ const void *a, _In_ const void *b) const + virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const { const keyseq - &ks_a = (const keyseq&)source[*(const unsigned __int32*)a], - &ks_b = (const keyseq&)source[*(const unsigned __int32*)b]; + &ks_a = (const keyseq&)a, + &ks_b = (const keyseq&)b; if (ks_a.chr < ks_b.chr) return -1; else if (ks_a.chr > ks_b.chr) return +1; @@ -130,18 +127,15 @@ namespace ZRCola { /// /// Key index /// - class indexKey : public index + class indexKey : public index { - protected: - std::vector &source; ///< Reference to source data - public: /// /// Constructs the index /// - /// \param[in] d Reference to vector holding the data + /// \param[in] h Reference to vector holding the data /// - indexKey(_In_ std::vector &s) : source(s) {} + indexKey(_In_ std::vector &h) : index(h) {} /// /// Compares two key sequences by key @@ -154,11 +148,11 @@ namespace ZRCola { /// - =0 when a == b /// - >0 when a > b /// - virtual int compare(_In_ const void *a, _In_ const void *b) const + virtual int compare(_In_ const unsigned __int16 &a, _In_ const unsigned __int16 &b) const { const keyseq - &ks_a = (const keyseq&)source[*(const unsigned __int32*)a], - &ks_b = (const keyseq&)source[*(const unsigned __int32*)b]; + &ks_a = (const keyseq&)a, + &ks_b = (const keyseq&)b; int r = keyseq::CompareSequence(ks_a.seq, ks_a.seq_len, ks_b.seq, ks_b.seq_len); if (r != 0) return r;