10 #include <boost/any.hpp> 11 #include <boost/version.hpp> 19 template <
typename TYPE>
20 static TYPE
get(
const boost::any& var) {
21 return var.type() ==
typeid(TYPE) ? boost::any_cast<TYPE>(var) : TYPE();
24 template <
typename TYPE,
typename VAR>
25 static TYPE
get(VAR var) {
26 #if BOOST_VERSION < 105800 27 return var.type() ==
typeid(TYPE) ? boost::get<TYPE>(var) : TYPE();
29 return var.type() ==
typeid(TYPE) ? boost::relaxed_get<TYPE>(var) : TYPE();
33 template <
typename TYPE,
typename VAR>
35 return (var.type() ==
typeid(TYPE));
38 static VariantNull
null() {
42 static bool isNull(
const boost::any& var) {
46 template <
typename VAR>
48 return typeOf<VariantNull>(var);
52 static int32_t
hashCode(
const NumericValue& var) {
53 if (typeOf<VariantNull>(var)) {
56 if (typeOf<int32_t>(var)) {
57 return get<int32_t>(var);
59 if (typeOf<int64_t>(var)) {
60 return (int32_t)get<int64_t>(var);
62 if (typeOf<double>(var)) {
64 return (int32_t)(longBits ^ (longBits >> 32));
69 template <
typename VAR>
71 if (typeOf<String>(var)) {
74 if (typeOf<int32_t>(var)) {
75 return get<int32_t>(var);
77 if (typeOf<int64_t>(var)) {
78 return (int32_t)get<int64_t>(var);
80 if (typeOf<double>(var)) {
82 return (int32_t)(longBits ^ (longBits >> 32));
85 return get< Collection<uint8_t> >(var).hashCode();
88 return get< Collection<int32_t> >(var).hashCode();
91 return get< Collection<int64_t> >(var).hashCode();
94 return get< Collection<double> >(var).hashCode();
97 return get< Collection<String> >(var).hashCode();
99 if (typeOf<LuceneObjectPtr>(var)) {
100 return get<LuceneObjectPtr>(var)->hashCode();
105 template <
typename FIRST,
typename SECOND>
107 return (first.type() == second.type());
110 template <
typename FIRST,
typename SECOND>
111 static bool equals(FIRST first, SECOND second) {
112 return first.type() == second.type() ? (first == second) :
false;
115 template <
typename VAR>
117 return first < second ? -1 : (first == second ? 0 : 1);
static bool isNull(const boost::any &var)
Definition: VariantUtils.h:42
static VariantNull null()
Definition: VariantUtils.h:38
static int64_t doubleToLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-poi...
static int32_t hashCode(const String &value)
Compute the hash code from string.
static bool typeOf(VAR var)
Definition: VariantUtils.h:34
static int32_t hashCode(VAR var)
Definition: VariantUtils.h:70
Definition: VariantUtils.h:17
Definition: AbstractAllTermDocs.h:12
static int32_t compareTo(VAR first, VAR second)
Definition: VariantUtils.h:116
static bool isNull(VAR var)
Definition: VariantUtils.h:47
static int32_t hashCode(const NumericValue &var)
Definition: VariantUtils.h:52
static bool equals(FIRST first, SECOND second)
Definition: VariantUtils.h:111
static bool equalsType(FIRST first, SECOND second)
Definition: VariantUtils.h:106