OpFlex Framework 1.7.0
ObjectInstance.h
Go to the documentation of this file.
1/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
6/*
7 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
8 *
9 * This program and the accompanying materials are made available under the
10 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11 * and is available at http://www.eclipse.org/legal/epl-v10.html
12 */
13
14#ifndef MODB_OBJECTINSTANCE_H_
15#define MODB_OBJECTINSTANCE_H_
16
17#include <string>
18#include <utility>
19#include <boost/tuple/tuple_comparison.hpp>
20#include <boost/cstdint.hpp>
21#include <boost/variant.hpp>
22
24#include "opflex/modb/URI.h"
25#include "opflex/modb/MAC.h"
26#include "opflex/ofcore/OFTypes.h"
27
28namespace opflex {
29namespace modb {
30
34typedef boost::tuple<PropertyInfo::property_type_t,
37
41typedef std::pair<class_id_t, URI> reference_t;
42
47size_t hash_value(prop_key_t const& key);
48
53size_t hash_value(reference_t const& key);
54
55} /* namespace modb */
56} /* namespace opflex */
57
58#if __cplusplus > 199711L
59
60namespace std {
65template<> struct hash<opflex::modb::prop_key_t> {
69 std::size_t operator()(const opflex::modb::prop_key_t& u) const {
71 }
72};
73
78template<> struct hash<opflex::modb::reference_t> {
82 std::size_t operator()(const opflex::modb::reference_t& p) const {
84 }
85};
86
87} /* namespace std */
88
89#endif
90
91namespace opflex {
92namespace modb {
93
94namespace mointernal {
95
104public:
111 : class_id(class_id_), local(true) { }
112
120 ObjectInstance(class_id_t class_id_, bool local_)
121 : class_id(class_id_), local(local_) { }
122
128 class_id_t getClassId() const { return class_id; }
129
136 bool isLocal() const { return local; }
137
147 bool isSet(prop_id_t prop_id,
150
160 bool unset(prop_id_t prop_id,
162 PropertyInfo::cardinality_t cardinality);
163
171 uint64_t getUInt64(prop_id_t prop_id) const;
172
182 uint64_t getUInt64(prop_id_t prop_id, size_t index) const;
183
191 size_t getUInt64Size(prop_id_t prop_id) const;
192
200 int64_t getInt64(prop_id_t prop_id) const;
201
211 int64_t getInt64(prop_id_t prop_id, size_t index) const;
212
220 size_t getInt64Size(prop_id_t prop_id) const;
221
228 const std::string& getString(prop_id_t prop_id) const;
229
239 const std::string& getString(prop_id_t prop_id, size_t index) const;
240
247 size_t getStringSize(prop_id_t prop_id) const;
248
256
266 reference_t getReference(prop_id_t prop_id, size_t index) const;
267
274 size_t getReferenceSize(prop_id_t prop_id) const;
275
283 const MAC& getMAC(prop_id_t prop_id) const;
284
294 const MAC& getMAC(prop_id_t prop_id, size_t index) const;
295
303 size_t getMACSize(prop_id_t prop_id) const;
304
313 void setUInt64(prop_id_t prop_id, uint64_t value);
314
323 void setUInt64(prop_id_t prop_id, const std::vector<uint64_t>& value);
324
333 void setString(prop_id_t prop_id, const std::string& value);
334
343 void setString(prop_id_t prop_id, const std::vector<std::string>& value);
344
353 void setInt64(prop_id_t prop_id, int64_t value);
354
363 void setInt64(prop_id_t prop_id, const std::vector<int64_t>& value);
364
375 class_id_t class_id, const URI& uri);
376
387 const std::vector<reference_t>& value);
388
397 void setMAC(prop_id_t prop_id, const MAC& value);
398
407 void setMAC(prop_id_t prop_id, const std::vector<MAC>& value);
408
417 void addUInt64(prop_id_t prop_id, uint64_t value);
418
427 void addInt64(prop_id_t prop_id, int64_t value);
428
437 void addString(prop_id_t prop_id, const std::string& value);
438
449 class_id_t class_id, const URI& uri);
450
459 void addMAC(prop_id_t prop_id, const MAC& value);
460
461private:
462 class_id_t class_id;
463
464 struct Value {
466 PropertyInfo::cardinality_t cardinality;
467 boost::variant<boost::blank,
468 uint64_t,
469 int64_t,
470 std::string,
472 MAC,
473 std::vector<uint64_t>*,
474 std::vector<int64_t>*,
475 std::vector<std::string>*,
476 std::vector<reference_t>*,
477 std::vector<MAC>*> value;
478
479 Value() {}
480 Value(const Value& val);
481 ~Value();
482 Value& operator=(const Value& val);
483 private:
484 void clear();
485 };
486
487 typedef OF_UNORDERED_MAP<prop_key_t, Value> prop_map_t;
488 prop_map_t prop_map;
489 bool local;
490
491 friend bool operator==(const ObjectInstance& lhs,
492 const ObjectInstance& rhs);
493 friend bool operator!=(const ObjectInstance& lhs,
494 const ObjectInstance& rhs);
495 friend bool operator==(const Value& lhs,
496 const Value& rhs);
497 friend bool operator!=(const Value& lhs,
498 const Value& rhs);
499 template <typename T>
500 friend bool equal(const Value& lhs, const Value& rhs);
501};
502
506bool operator==(const ObjectInstance& lhs, const ObjectInstance& rhs);
510bool operator!=(const ObjectInstance& lhs, const ObjectInstance& rhs);
511
512} /* namespace mointernal */
513} /* namespace modb */
514} /* namespace opflex */
515
516#endif /* MODB_OBJECTINSTANCE_H_ */
Interface definition file for MACs.
bool operator==(const MO &lhs, const MO &rhs)
Check for MO equality.
bool operator!=(const MO &lhs, const MO &rhs)
Check for MO inequality.
boost::tuple< PropertyInfo::property_type_t, PropertyInfo::cardinality_t, prop_id_t > prop_key_t
A tuple containing the key for a property value.
Definition ObjectInstance.h:36
std::pair< class_id_t, URI > reference_t
A URI reference containing a class ID and a URI pair.
Definition ObjectInstance.h:41
Interface definition file for PropertyInfo.
Interface definition file for URIs.
A MAC address is used to identify devices on an ethernet network.
Definition MAC.h:37
A URI is used to identify managed objects in the MODB.
Definition URI.h:43
An internal instance of an object in the managed object store.
Definition ObjectInstance.h:103
void setInt64(prop_id_t prop_id, const std::vector< int64_t > &value)
Set the int64-vector-valued parameter to the specified value.
void setMAC(prop_id_t prop_id, const std::vector< MAC > &value)
Set the MAC address-vector-valued parameter to the specified value.
reference_t getReference(prop_id_t prop_id) const
Get the reference-valued property for prop_name.
const MAC & getMAC(prop_id_t prop_id) const
Get the MAC-address-valued property for prop_name.
void setUInt64(prop_id_t prop_id, uint64_t value)
Set the uint64-valued parameter to the specified value.
void setString(prop_id_t prop_id, const std::string &value)
Set the string-valued parameter to the specified value.
const MAC & getMAC(prop_id_t prop_id, size_t index) const
For a vector-valued MAC address property, get the specified property value at the specified index.
size_t getInt64Size(prop_id_t prop_id) const
Get the number of signed 64-bit values for the specified property.
void setMAC(prop_id_t prop_id, const MAC &value)
Set the MAC address-valued parameter to the specified value.
size_t getReferenceSize(prop_id_t prop_id) const
Get the number of reference values for the specified property.
void addReference(prop_id_t prop_id, class_id_t class_id, const URI &uri)
Add a value to a the specified reference vector.
void setString(prop_id_t prop_id, const std::vector< std::string > &value)
Set the string-vector-valued parameter to the specified vector.
bool isSet(prop_id_t prop_id, PropertyInfo::property_type_t type, PropertyInfo::cardinality_t cardinality=PropertyInfo::SCALAR) const
Check whether the given property is set.
void addUInt64(prop_id_t prop_id, uint64_t value)
Add a value to a the specified unsigned 64-bit vector.
friend bool operator==(const ObjectInstance &lhs, const ObjectInstance &rhs)
Check for ObjectInstance equality.
bool isLocal() const
Return whether the object was from the remote policy repository or was written locally.
Definition ObjectInstance.h:136
ObjectInstance(class_id_t class_id_, bool local_)
Construct an empty object represented the specified class and using the provided local flag.
Definition ObjectInstance.h:120
void setReference(prop_id_t prop_id, const std::vector< reference_t > &value)
Set the reference-vector-valued parameter to the specified vector.
void addString(prop_id_t prop_id, const std::string &value)
Add a value to a the specified string vector.
size_t getUInt64Size(prop_id_t prop_id) const
Get the number of unsigned 64-bit values for the specified property.
const std::string & getString(prop_id_t prop_id) const
Get the string-valued property for prop_name.
class_id_t getClassId() const
Get the class ID for this object instance.
Definition ObjectInstance.h:128
int64_t getInt64(prop_id_t prop_id, size_t index) const
For a vector-valued 64-bit signed property, get the specified property value at the specified index.
ObjectInstance(class_id_t class_id_)
Construct an empty object represented the specified class.
Definition ObjectInstance.h:110
int64_t getInt64(prop_id_t prop_id) const
Get the signed 64-bit valued property for prop_name.
uint64_t getUInt64(prop_id_t prop_id) const
Get the unsigned 64-bit valued property for prop_name.
bool unset(prop_id_t prop_id, PropertyInfo::property_type_t type, PropertyInfo::cardinality_t cardinality)
Unset the given property.
void addMAC(prop_id_t prop_id, const MAC &value)
Add a value to a the specified MAC address vector.
void addInt64(prop_id_t prop_id, int64_t value)
Add a value to a the specified signed 64-bit vector.
size_t getStringSize(prop_id_t prop_id) const
Get the number of string values for the specified property.
uint64_t getUInt64(prop_id_t prop_id, size_t index) const
For a vector-valued 64-bit unsigned property, get the specified property value at the specified index...
friend bool operator!=(const ObjectInstance &lhs, const ObjectInstance &rhs)
Check for ObjectInstance inequality.
size_t getMACSize(prop_id_t prop_id) const
Get the number of MAC address values for the specified property.
void setUInt64(prop_id_t prop_id, const std::vector< uint64_t > &value)
Set the uint64-vector-valued parameter to the specified value.
void setReference(prop_id_t prop_id, class_id_t class_id, const URI &uri)
Set the reference-valued parameter to the specified value.
const std::string & getString(prop_id_t prop_id, size_t index) const
For a vector-valued string property, get the specified property value at the specified index.
reference_t getReference(prop_id_t prop_id, size_t index) const
For a vector-valued reference property, get the specified property value at the specified index.
void setInt64(prop_id_t prop_id, int64_t value)
Set the int64-valued parameter to the specified value.
uint64_t prop_id_t
A unique property ID.
Definition PropertyInfo.h:39
uint64_t class_id_t
A unique class ID.
Definition PropertyInfo.h:34
property_type_t
Possible property types.
Definition PropertyInfo.h:54
cardinality_t
Enum representing the cardinality of the property.
Definition PropertyInfo.h:82
@ SCALAR
A scalar-valued property.
Definition PropertyInfo.h:84
size_t hash_value(MAC const &mac)
Compute a hash value for the MAC, making MAC suitable as a key in a boost::unordered_map.