ProductID.hpp 3.02 KB
Newer Older
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
126
127
128
129
130
131
132
133
134
/*
 * (C) 2018 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
#ifndef __HEPNOS_PRODUCT_ID_H
#define __HEPNOS_PRODUCT_ID_H

#include <string>

#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>

#include <hepnos/DataStore.hpp>

namespace hepnos {

class ProductID {

    friend class DataStore;
    friend class DataStore::Impl;
    friend class boost::serialization::access;

    private:

    std::uint8_t m_level;
    std::string  m_containerName;
    std::string  m_objectName;

    ProductID(std::uint8_t level, const std::string& containerName, const std::string& objectName)
    : m_level(level)
    , m_containerName(containerName)
    , m_objectName(objectName) {}

    public:

    ProductID() = default;

    /**
     * @brief Copy constructor.
     *
     * @param other ProductID to copy.
     */
    ProductID(const ProductID& other) = default;

    /**
     * @brief Move constructor.
     *
     * @param other ProductID to move.
     */
    ProductID(ProductID&& other) = default;

    /**
     * @brief Copy-assignment operator.
     *
     * @param other ProductID to assign.
     *
     * @return Reference to this ProductID.
     */
    ProductID& operator=(const ProductID& other) = default;

    /**
     * @brief Move-assignment operator.
     *
     * @param other ProductID to move from.
     *
     * @return Reference to this ProductID.
     */
    ProductID& operator=(ProductID&& other) = default;

    /**
     * @brief Destructor.
     */
    ~ProductID() = default;

    /**
     * @brief Indicates whether this ProductID instance points to a valid
     * product in the underlying storage service.
     *
     * @return True if the ProductID instance points to a valid product in the
     * underlying service, false otherwise.
     */
    bool valid() const {
        return m_objectName.size() != 0;
    }

    /**
     * @brief Conversion to bool.
     *
     * @return True if the ProductID instance points to a valid product in the
     * underlying service, false otherwise.
     */
    inline operator bool() const {
        return valid();
    }

    /**
     * @brief Compares this ProductID with another ProductID.
     *
     * @param other ProductID instance to compare against.
     *
     * @return true if the ProductIDs are the same, false otherwise.
     */
    bool operator==(const ProductID& other) const {
        return m_level == other.m_level
            && m_containerName == other.m_containerName
            && m_objectName == other.m_objectName;
    }

    /**
     * @brief Compares this ProductID with another ProductID.
     *
     * @param other ProductID instance to compare against.
     *
     * @return true if the ProductIDs are different, false otherwise.
     */
    bool operator!=(const ProductID& other) const {
        return !(*this == other);
    }

    private:

    template<typename Archive>
    void serialize(Archive& ar, const unsigned int version) {
        ar & m_level;
        ar & m_containerName;
        ar & m_objectName;
    }

};

}

#endif