123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #ifndef MYSQLX_COLLATIONS_H
- #define MYSQLX_COLLATIONS_H
- #include "common.h"
- #include "mysql_charsets.h"
- #include "mysql_collations.h"
- namespace mysqlx {
- enum class CharacterSet : unsigned short
- {
- #undef CS
- #define CS_ENUM(CS) CS,
- CDK_CS_LIST(CS_ENUM)
- };
- #define CS_NAME_SWITCH(CS) case CharacterSet::CS: return #CS;
- inline
- const char* characterSetName(CharacterSet id)
- {
- switch (id)
- {
- CDK_CS_LIST(CS_NAME_SWITCH)
- default:
- THROW("Unknown character set id");
- }
- }
- struct CollationInfo
- {
-
- unsigned id() const { return m_id; }
-
- const char *getName() const { return m_name; }
-
- CharacterSet getCharacterSet() const { return m_cs; }
-
- bool isCaseSensitive() const { return m_case != case_ci; }
-
- bool isBinary() const { return m_case == case_bin; }
- bool operator==(const CollationInfo &other) const
- {
- return m_id == other.m_id;
- }
- bool operator!=(const CollationInfo &other) const
- {
- return !operator==(other);
- }
- private:
- enum coll_case { case_bin, case_ci, case_cs };
- CharacterSet m_cs;
- unsigned m_id;
- coll_case m_case;
- const char *m_name;
- public:
- struct Access;
- friend Access;
- };
- template <CharacterSet CS> struct Collation;
- #define COLL_DECL(CS) \
- template<> struct Collation<CharacterSet::CS> \
- { COLLATIONS_##CS(COLL_CONST) }; \
- #define COLL_CONST(CS,ID,COLL,CASE) \
- static PUBLIC_API const CollationInfo COLL_CONST_NAME(COLL,CASE);
- #define COLL_CONST_NAME(COLL,CASE) COLL_CONST_NAME_##CASE(COLL)
- #define COLL_CONST_NAME_bin(COLL) COLL
- #define COLL_CONST_NAME_ci(COLL) COLL##_ci
- #define COLL_CONST_NAME_cs(COLL) COLL##_cs
- CDK_CS_LIST(COLL_DECL)
- }
- #endif
|