summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/broker/SelectorValue.h
blob: aa2197b2255a155e0133f84446379e2f43f780b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef QPID_BROKER_SELECTORVALUE_H
#define QPID_BROKER_SELECTORVALUE_H

/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

#include "qpid/sys/IntegerTypes.h"

#include <iosfwd>
#include <string>

namespace qpid {
namespace broker {

enum BoolOrNone {
    BN_FALSE = false,
    BN_TRUE = true,
    BN_UNKNOWN
};

// The user of the Value class for strings must ensure that
// the string has a lifetime longer than the string used and
// is responsible for managing its lifetime.
class Value {
public:
    union {
        bool               b;
        int64_t            i;
        double             x;
        const std::string* s;
    };
    enum {
        T_UNKNOWN,
        T_BOOL,
        T_STRING,
        T_EXACT,
        T_INEXACT
    } type;

    // Default copy contructor
    // Default assignment operator
    // Default destructor
    Value() :
        type(T_UNKNOWN)
    {}

    Value(const std::string& s0) :
        s(&s0),
        type(T_STRING)
    {}

    Value(const int64_t i0) :
        i(i0),
        type(T_EXACT)
    {}

    Value(const int32_t i0) :
        i(i0),
        type(T_EXACT)
    {}

    Value(const double x0) :
        x(x0),
        type(T_INEXACT)
    {}

    Value(bool b0) :
        b(b0),
        type(T_BOOL)
    {}

    Value(BoolOrNone bn) :
        b(bn),
        type(bn==BN_UNKNOWN ? T_UNKNOWN : T_BOOL)
    {}
};

inline bool unknown(const Value& v) {
    return v.type == Value::T_UNKNOWN;
}

inline bool numeric(const Value& v) {
    return v.type == Value::T_EXACT || v.type == Value::T_INEXACT;
}

inline bool sameType(const Value& v1, const Value& v2) {
    return v1.type == v2.type;
}

std::ostream& operator<<(std::ostream& os, const Value& v);

bool operator==(const Value&, const Value&);
bool operator!=(const Value&, const Value&);
bool operator<(const Value&, const Value&);
bool operator>(const Value&, const Value&);
bool operator<=(const Value&, const Value&);
bool operator>=(const Value&, const Value&);

Value operator+(const Value&, const Value&);
Value operator-(const Value&, const Value&);
Value operator*(const Value&, const Value&);
Value operator/(const Value&, const Value&);
Value operator-(const Value&);

}}

#endif