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);
51 template <
typename VAR>
53 if (typeOf<String>(var)) {
54 return StringUtils::hashCode(get<String>(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)) {
63 int64_t longBits = MiscUtils::doubleToLongBits(get<double>(var));
64 return (int32_t)(longBits ^ (longBits >> 32));
67 return get< Collection<uint8_t> >(var).hashCode();
70 return get< Collection<int32_t> >(var).hashCode();
73 return get< Collection<int64_t> >(var).hashCode();
76 return get< Collection<double> >(var).hashCode();
79 return get< Collection<String> >(var).hashCode();
81 if (typeOf<LuceneObjectPtr>(var)) {
82 return get<LuceneObjectPtr>(var)->hashCode();
87 template <
typename FIRST,
typename SECOND>
89 return (first.type() == second.type());
92 template <
typename FIRST,
typename SECOND>
93 static bool equals(FIRST first, SECOND second) {
94 return first.type() == second.type() ? (first == second) :
false;
97 template <
typename VAR>
99 return first < second ? -1 : (first == second ? 0 : 1);
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
Definition VariantUtils.h:17
static TYPE get(const boost::any &var)
Definition VariantUtils.h:20
static int32_t hashCode(VAR var)
Definition VariantUtils.h:52
static bool isNull(VAR var)
Definition VariantUtils.h:47
static bool typeOf(VAR var)
Definition VariantUtils.h:34
static bool isNull(const boost::any &var)
Definition VariantUtils.h:42
static bool equalsType(FIRST first, SECOND second)
Definition VariantUtils.h:88
static int32_t compareTo(VAR first, VAR second)
Definition VariantUtils.h:98
static TYPE get(VAR var)
Definition VariantUtils.h:25
static VariantNull null()
Definition VariantUtils.h:38
static bool equals(FIRST first, SECOND second)
Definition VariantUtils.h:93
Definition AbstractAllTermDocs.h:12