OpFlex Framework  1.5.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 
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 
53 size_t hash_value(reference_t const& key);
54 
55 } /* namespace modb */
56 } /* namespace opflex */
57 
58 #if __cplusplus > 199711L
59 
60 namespace std {
65 template<> struct hash<opflex::modb::prop_key_t> {
69  std::size_t operator()(const opflex::modb::prop_key_t& u) const {
70  return opflex::modb::hash_value(u);
71  }
72 };
73 
78 template<> struct hash<opflex::modb::reference_t> {
82  std::size_t operator()(const opflex::modb::reference_t& p) const {
83  return opflex::modb::hash_value(p);
84  }
85 };
86 
87 } /* namespace std */
88 
89 #endif
90 
91 namespace opflex {
92 namespace modb {
93 
94 namespace mointernal {
95 
104 public:
110  ObjectInstance(class_id_t class_id_) : class_id(class_id_) { }
111 
117  class_id_t getClassId() const { return class_id; }
118 
128  bool isSet(prop_id_t prop_id,
131 
141  bool unset(prop_id_t prop_id,
143  PropertyInfo::cardinality_t cardinality);
144 
152  uint64_t getUInt64(prop_id_t prop_id) const;
153 
163  uint64_t getUInt64(prop_id_t prop_id, size_t index) const;
164 
172  size_t getUInt64Size(prop_id_t prop_id) const;
173 
181  int64_t getInt64(prop_id_t prop_id) const;
182 
192  int64_t getInt64(prop_id_t prop_id, size_t index) const;
193 
201  size_t getInt64Size(prop_id_t prop_id) const;
202 
209  const std::string& getString(prop_id_t prop_id) const;
210 
220  const std::string& getString(prop_id_t prop_id, size_t index) const;
221 
228  size_t getStringSize(prop_id_t prop_id) const;
229 
236  reference_t getReference(prop_id_t prop_id) const;
237 
247  reference_t getReference(prop_id_t prop_id, size_t index) const;
248 
255  size_t getReferenceSize(prop_id_t prop_id) const;
256 
264  const MAC& getMAC(prop_id_t prop_id) const;
265 
275  const MAC& getMAC(prop_id_t prop_id, size_t index) const;
276 
284  size_t getMACSize(prop_id_t prop_id) const;
285 
294  void setUInt64(prop_id_t prop_id, uint64_t value);
295 
304  void setUInt64(prop_id_t prop_id, const std::vector<uint64_t>& value);
305 
314  void setString(prop_id_t prop_id, const std::string& value);
315 
324  void setString(prop_id_t prop_id, const std::vector<std::string>& value);
325 
334  void setInt64(prop_id_t prop_id, int64_t value);
335 
344  void setInt64(prop_id_t prop_id, const std::vector<int64_t>& value);
345 
355  void setReference(prop_id_t prop_id,
356  class_id_t class_id, const URI& uri);
357 
367  void setReference(prop_id_t prop_id,
368  const std::vector<reference_t>& value);
369 
378  void setMAC(prop_id_t prop_id, const MAC& value);
379 
388  void setMAC(prop_id_t prop_id, const std::vector<MAC>& value);
389 
398  void addUInt64(prop_id_t prop_id, uint64_t value);
399 
408  void addInt64(prop_id_t prop_id, int64_t value);
409 
418  void addString(prop_id_t prop_id, const std::string& value);
419 
429  void addReference(prop_id_t prop_id,
430  class_id_t class_id, const URI& uri);
431 
440  void addMAC(prop_id_t prop_id, const MAC& value);
441 
442 private:
443  class_id_t class_id;
444 
445  struct Value {
447  PropertyInfo::cardinality_t cardinality;
448  boost::variant<boost::blank,
449  uint64_t,
450  int64_t,
451  std::string,
452  reference_t,
453  MAC,
454  std::vector<uint64_t>*,
455  std::vector<int64_t>*,
456  std::vector<std::string>*,
457  std::vector<reference_t>*,
458  std::vector<MAC>*> value;
459 
460  Value() {}
461  Value(const Value& val);
462  ~Value();
463  Value& operator=(const Value& val);
464  private:
465  void clear();
466  };
467 
468  typedef OF_UNORDERED_MAP<prop_key_t, Value> prop_map_t;
469  prop_map_t prop_map;
470 
471  friend bool operator==(const ObjectInstance& lhs,
472  const ObjectInstance& rhs);
473  friend bool operator!=(const ObjectInstance& lhs,
474  const ObjectInstance& rhs);
475  friend bool operator==(const Value& lhs,
476  const Value& rhs);
477  friend bool operator!=(const Value& lhs,
478  const Value& rhs);
479  template <typename T>
480  friend bool equal(const Value& lhs, const Value& rhs);
481 };
482 
486 bool operator==(const ObjectInstance& lhs, const ObjectInstance& rhs);
490 bool operator!=(const ObjectInstance& lhs, const ObjectInstance& rhs);
491 
492 } /* namespace mointernal */
493 } /* namespace modb */
494 } /* namespace opflex */
495 
496 #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:84
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:82
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.
size_t hash_value(URI const &uri)
Compute a hash value for the URI, making URI suitable as a key in a boost::unordered_map.
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:103
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:34
ObjectInstance(class_id_t class_id_)
Construct an empty object represented the specified class.
Definition: ObjectInstance.h:110
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:43
uint64_t prop_id_t
A unique property ID.
Definition: PropertyInfo.h:39
class_id_t getClassId() const
Get the class ID for this object instance.
Definition: ObjectInstance.h:117
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:54
A MAC address is used to identify devices on an ethernet network.
Definition: MAC.h:37
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 a boost::unordered_map.