14 #ifndef OPFLEX_CORE_MO_H
15 #define OPFLEX_CORE_MO_H
19 #include <boost/make_shared.hpp>
20 #include <boost/ref.hpp>
21 #include <boost/optional.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/noncopyable.hpp>
31 namespace mointernal {
49 class MO :
private boost::noncopyable {
84 const boost::shared_ptr<const ObjectInstance>& oi);
97 const boost::shared_ptr<const ObjectInstance>& oi);
124 static boost::shared_ptr<const ObjectInstance>
165 template <
class T>
static
166 boost::optional<boost::shared_ptr<T> >
171 return boost::make_shared<T>(boost::ref(framework), uri,
173 }
catch (std::out_of_range e) {
182 template <
class T>
static
185 const URI& parent_uri,
188 std::vector<boost::shared_ptr<T> >& out) {
189 std::vector<URI> childURIs;
191 .
getChildren(parent_class, parent_uri, parent_prop,
192 child_class, childURIs);
193 std::vector<URI>::const_iterator it;
194 for (it = childURIs.begin(); it != childURIs.end(); ++it) {
195 boost::optional<boost::shared_ptr<T> > child =
196 resolve<T>(framework, child_class, *it);
197 if (child) out.push_back(child.get());
207 const URI& parent_uri,
210 const URI& child_uri) {
211 return boost::make_shared<T>(boost::ref(
getFramework()),
224 static boost::shared_ptr<T>
227 return boost::make_shared<T>(boost::ref(framework),
229 framework.getTLMutator()
230 .
modify(class_id, URI::ROOT));
239 framework.getTLMutator().
remove(class_id, uri);
254 bool operator==(
const MO& lhs,
const MO& rhs);
258 bool operator!=(
const MO& lhs,
const MO& rhs);
A client for accessing the object store scoped to an owner.
Definition: StoreClient.h:39
bool operator==(const MAC &lhs, const MAC &rhs)
Check for MAC equality.
This is the base class for all managed objects, which are the primary point of interface with data st...
Definition: MO.h:49
static StoreClient & getStoreClient(ofcore::OFFramework &framework)
Get a read-only store client for the framework instance.
A mutator represents a set of changes to apply to the data store.
Definition: Mutator.h:60
MO(class_id_t class_id, const URI &uri, const boost::shared_ptr< const ObjectInstance > &oi)
Construct an MO.
class_id_t getClassId() const
Get the class ID associated with this managed object.
Interface definition file for MODB.
const URI & getURI() const
Get the URI associated with this managed object.
Interface for an object interested in updates to objects in the data store.
Definition: ObjectListener.h:41
Main interface to the OpFlex framework.
Definition: OFFramework.h:644
static const URI ROOT
Static root URI.
Definition: URI.h:82
friend bool operator==(const MO &lhs, const MO &rhs)
Check for MO equality.
const ObjectInstance & getObjectInstance() const
Get the raw object instance associated with this managed object.
static boost::optional< boost::shared_ptr< T > > resolve(ofcore::OFFramework &framework, class_id_t class_id, const URI &uri)
Resolve the specified URI to its managed object wrapper class, if it exists.
Definition: MO.h:167
void getChildren(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, std::vector< URI > &output)
Get the children of the parent URI and property and put the result into the supplied vector...
static void registerListener(ofcore::OFFramework &framework, ObjectListener *listener, class_id_t class_id)
Register the listener for the specified class ID.
boost::shared_ptr< T > addChild(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, const URI &child_uri)
Add a child of the specified type to the mutator and instantiate the correct wrapper class...
Definition: MO.h:206
static boost::shared_ptr< T > createRootElement(ofcore::OFFramework &framework, class_id_t class_id)
Add a root element of the given type to the framework.
Definition: MO.h:225
ofcore::OFFramework & getFramework() const
Get the framework instance associated with this managed object.
virtual ~MO()
Destroy an MO.
friend bool operator!=(const MO &lhs, const MO &rhs)
Check for MO inequality.
An internal instance of an object in the managed object store.
Definition: ObjectInstance.h:58
void remove(class_id_t class_id, const URI &uri)
Delete the child object specified along with its link to its parents.
boost::shared_ptr< mointernal::ObjectInstance > & addChild(class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, const URI &child_uri)
Create a new child object with the specified class and URI, and make it a child of the given parent...
Mutator & getTLMutator()
Get the currently-active mutator.
static void resolveChildren(ofcore::OFFramework &framework, class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, std::vector< boost::shared_ptr< T > > &out)
Resolve any children of the specified parent object to their managed object wrapper classes...
Definition: MO.h:183
bool operator!=(const MAC &lhs, const MAC &rhs)
Check for MAC inequality.
boost::shared_ptr< mointernal::ObjectInstance > & modify(class_id_t class_id, const URI &uri)
Create a new mutable object with the given URI which is a copy of any existing object with the specif...
A URI is used to identify managed objects in the MODB.
Definition: URI.h:41
Interface definition file for OFFramework.
static boost::shared_ptr< const ObjectInstance > resolveOI(ofcore::OFFramework &framework, class_id_t class_id, const URI &uri)
Resolve the specified URI to the underlying object instance, if it exists.
static void unregisterListener(ofcore::OFFramework &framework, ObjectListener *listener, class_id_t class_id)
Unregister the listener for the specified class ID.
Interface definition file for ObjectListeners.