OpFlex Framework  1.3.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/unordered_map.hpp>
22 #include <boost/variant.hpp>
23 
25 #include "opflex/modb/URI.h"
26 #include "opflex/modb/MAC.h"
27 
28 namespace opflex {
29 namespace modb {
30 
34 typedef boost::tuple<PropertyInfo::property_type_t,
36  prop_id_t> prop_key_t;
37 
41 typedef std::pair<class_id_t, URI> reference_t;
42 
47 size_t hash_value(prop_key_t const& key);
48 
49 namespace mointernal {
50 
59 public:
65  ObjectInstance(class_id_t class_id_) : class_id(class_id_) { }
66 
72  class_id_t getClassId() const { return class_id; }
73 
83  bool isSet(prop_id_t prop_id,
86 
96  bool unset(prop_id_t prop_id,
98  PropertyInfo::cardinality_t cardinality);
99 
107  uint64_t getUInt64(prop_id_t prop_id) const;
108 
118  uint64_t getUInt64(prop_id_t prop_id, size_t index) const;
119 
127  size_t getUInt64Size(prop_id_t prop_id) const;
128 
136  int64_t getInt64(prop_id_t prop_id) const;
137 
147  int64_t getInt64(prop_id_t prop_id, size_t index) const;
148 
156  size_t getInt64Size(prop_id_t prop_id) const;
157 
164  const std::string& getString(prop_id_t prop_id) const;
165 
175  const std::string& getString(prop_id_t prop_id, size_t index) const;
176 
183  size_t getStringSize(prop_id_t prop_id) const;
184 
191  reference_t getReference(prop_id_t prop_id) const;
192 
202  reference_t getReference(prop_id_t prop_id, size_t index) const;
203 
210  size_t getReferenceSize(prop_id_t prop_id) const;
211 
219  const MAC& getMAC(prop_id_t prop_id) const;
220 
230  const MAC& getMAC(prop_id_t prop_id, size_t index) const;
231 
239  size_t getMACSize(prop_id_t prop_id) const;
240 
249  void setUInt64(prop_id_t prop_id, uint64_t value);
250 
259  void setUInt64(prop_id_t prop_id, const std::vector<uint64_t>& value);
260 
269  void setString(prop_id_t prop_id, const std::string& value);
270 
279  void setString(prop_id_t prop_id, const std::vector<std::string>& value);
280 
289  void setInt64(prop_id_t prop_id, int64_t value);
290 
299  void setInt64(prop_id_t prop_id, const std::vector<int64_t>& value);
300 
310  void setReference(prop_id_t prop_id,
311  class_id_t class_id, const URI& uri);
312 
322  void setReference(prop_id_t prop_id,
323  const std::vector<reference_t>& value);
324 
333  void setMAC(prop_id_t prop_id, const MAC& value);
334 
343  void setMAC(prop_id_t prop_id, const std::vector<MAC>& value);
344 
353  void addUInt64(prop_id_t prop_id, uint64_t value);
354 
363  void addInt64(prop_id_t prop_id, int64_t value);
364 
373  void addString(prop_id_t prop_id, const std::string& value);
374 
384  void addReference(prop_id_t prop_id,
385  class_id_t class_id, const URI& uri);
386 
395  void addMAC(prop_id_t prop_id, const MAC& value);
396 
397 private:
398  class_id_t class_id;
399 
400  struct Value {
402  PropertyInfo::cardinality_t cardinality;
403  boost::variant<boost::blank,
404  uint64_t,
405  int64_t,
406  std::string,
407  reference_t,
408  MAC,
409  std::vector<uint64_t>*,
410  std::vector<int64_t>*,
411  std::vector<std::string>*,
412  std::vector<reference_t>*,
413  std::vector<MAC>*> value;
414 
415  Value() {}
416  Value(const Value& val);
417  ~Value();
418  Value& operator=(const Value& val);
419  private:
420  void clear();
421  };
422 
423  typedef boost::unordered_map<prop_key_t, Value> prop_map_t;
424  prop_map_t prop_map;
425 
426  friend bool operator==(const ObjectInstance& lhs,
427  const ObjectInstance& rhs);
428  friend bool operator!=(const ObjectInstance& lhs,
429  const ObjectInstance& rhs);
430  friend bool operator==(const Value& lhs,
431  const Value& rhs);
432  friend bool operator!=(const Value& lhs,
433  const Value& rhs);
434  template <typename T>
435  friend bool equal(const Value& lhs, const Value& rhs);
436 };
437 
441 bool operator==(const ObjectInstance& lhs, const ObjectInstance& rhs);
445 bool operator!=(const ObjectInstance& lhs, const ObjectInstance& rhs);
446 
447 } /* namespace mointernal */
448 } /* namespace modb */
449 } /* namespace opflex */
450 
451 #endif /* MODB_OBJECTINSTANCE_H_ */
size_t getStringSize(prop_id_t prop_id) const
Get the number of string values for the specified property.
bool unset(prop_id_t prop_id, PropertyInfo::property_type_t type, PropertyInfo::cardinality_t cardinality)
Unset the given property.
void setInt64(prop_id_t prop_id, int64_t value)
Set the int64-valued parameter to the specified value.
Interface definition file for MACs.
A scalar-valued property.
Definition: PropertyInfo.h:86
void setUInt64(prop_id_t prop_id, uint64_t value)
Set the uint64-valued parameter to the specified value.
size_t getInt64Size(prop_id_t prop_id) const
Get the number of signed 64-bit values for the specified property.
void addUInt64(prop_id_t prop_id, uint64_t value)
Add a value to a the specified unsigned 64-bit vector.
cardinality_t
Enum representing the cardinality of the property.
Definition: PropertyInfo.h:84
int64_t getInt64(prop_id_t prop_id) const
Get the signed 64-bit valued property for prop_name.
void setReference(prop_id_t prop_id, class_id_t class_id, const URI &uri)
Set the reference-valued parameter to the specified value.
Interface definition file for PropertyInfo.
void setMAC(prop_id_t prop_id, const MAC &value)
Set the MAC address-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.
void addInt64(prop_id_t prop_id, int64_t value)
Add a value to a the specified signed 64-bit 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.
An internal instance of an object in the managed object store.
Definition: ObjectInstance.h:58
size_t getMACSize(prop_id_t prop_id) const
Get the number of MAC address values for the specified property.
uint64_t class_id_t
A unique class ID.
Definition: PropertyInfo.h:36
ObjectInstance(class_id_t class_id_)
Construct an empty object represented the specified class.
Definition: ObjectInstance.h:65
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.
void addReference(prop_id_t prop_id, class_id_t class_id, const URI &uri)
Add a value to a the specified reference vector.
A URI is used to identify managed objects in the MODB.
Definition: URI.h:41
uint64_t prop_id_t
A unique property ID.
Definition: PropertyInfo.h:41
class_id_t getClassId() const
Get the class ID for this object instance.
Definition: ObjectInstance.h:72
const MAC & getMAC(prop_id_t prop_id) const
Get the MAC-address-valued property for prop_name.
size_t getReferenceSize(prop_id_t prop_id) const
Get the number of reference values for the specified property.
Interface definition file for URIs.
void addMAC(prop_id_t prop_id, const MAC &value)
Add a value to a the specified MAC address vector.
const std::string & getString(prop_id_t prop_id) const
Get the string-valued property for prop_name.
property_type_t
Possible property types.
Definition: PropertyInfo.h:56
A MAC address is used to identify devices on an ethernet network.
Definition: MAC.h:40
friend bool operator==(const ObjectInstance &lhs, const ObjectInstance &rhs)
Check for ObjectInstance equality.
uint64_t getUInt64(prop_id_t prop_id) const
Get the unsigned 64-bit valued property for prop_name.
friend bool operator!=(const ObjectInstance &lhs, const ObjectInstance &rhs)
Check for ObjectInstance inequality.
reference_t getReference(prop_id_t prop_id) const
Get the reference-valued property for prop_name.
size_t hash_value(MAC const &mac)
Compute a hash value for the MAC, making MAC suitable as a key in an unordered_map.