How to create new Entities in MemoryX
  • define a class in slice which inherits from EntityBase and add custom accessor methods
    #include <MemoryX/interface/core/EntityBase.ice>
    {
    ["cpp:virtual"]
    class CountBase extends EntityBase
    {
    ["cpp:const"]
    int getCount();
    void setCount(int count);
    };
    };
  • Define C++ class
    #ifndef ARMARX_MEMORYX_CORE_COUNT_ENTITY_H_
    #define ARMARX_MEMORYX_CORE_COUNT_ENTITY_H_
    #include <MemoryX/interface/core/EntityBase.h>
    #include <MemoryX/interface/memorytypes/MyNewEntities.h>
    // the following is required for the friend class declaration used together with private/protected constructors
    // see http://stackoverflow.com/a/2060691
    //
    //namespace armarx
    //{
    // template <class IceBaseClass, class DerivedClass> class GenericFactory;
    //}
    namespace memoryx
    {
    class Count;
    using CountPtr = IceInternal::Handle<Count>;
    class Count :
    public memoryx::CountBase,
    {
    // add this line if you want to make your constructor private/protected
    // you also need to uncomment the namespace declaration for this to work
    // template <class IceBaseClass, class DerivedClass> friend class armarx::GenericFactory;
    public:
    Count();
    Count(const Count& source);
    virtual ~Count();
    // cloning
    Ice::ObjectPtr ice_clone() const;
    CountPtr clone(const Ice::Current& c = Ice::emptyCurrent) const;
    // interface
    Ice::Int getCount(const Ice::Current& context = Ice::emptyCurrent) const;
    void setCount(Ice::Int count, const Ice::Current& context = Ice::emptyCurrent);
    private:
    void output(std::ostream &stream) const;
    public:
    // streaming operator
    friend std::ostream &operator<<(std::ostream &stream, const Count& rhs)
    {
    rhs.output(stream);
    return stream;
    }
    friend std::ostream &operator<<(std::ostream &stream, const CountPtr& rhs)
    {
    rhs->output(stream);
    return stream;
    }
    friend std::ostream &operator<<(std::ostream &stream, const CountBasePtr& rhs)
    {
    stream << CountPtr::dynamicCast(rhs);
    return stream;
    }
    };
    }
    #endif
  • implement C++ class
    #include "Count.h"
    namespace memoryx
    {
    Count::Count() :
    Entity()
    {
    EntityAttributePtr countAttribute = new EntityAttribute("count");
    putAttribute(countAttribute);
    }
    Count::Count(const Count& source):
    IceUtil::Shared(source),
    ::armarx::Serializable(source),
    EntityBase(),// dont copy
    CountBase(source),
    Entity(source)
    {
    }
    Count::~Count()
    {
    }
    void Count::output(std::ostream &stream) const
    {
    Entity::output(stream);
    }
    Ice::ObjectPtr Count::ice_clone() const
    {
    return this->clone();
    }
    CountPtr Count::clone(const Ice::Current& c) const
    {
    boost::shared_lock<boost::shared_mutex> entityLock(entityMutex);
    armarx::ScopedLock attributesLock(attributesMutex);
    armarx::RecursiveMutex::scoped_lock wrappersLock(wrappersMutex);
    CountPtr ret = new Count(*this);
    return ret;
    }
    Ice::Int Count::getCount(const Ice::Current& context) const
    {
    return getAttribute("count")->getValue()->getInt();
    }
    void Count::setCount(Ice::Int count, const Ice::Current& context)
    {
    getAttribute("count")->setValue(new armarx::Variant(count));
    }
    }
  • add files to a library SOURCES/HEADERS variables in respective CMakeLists.txt
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ObjectFactoryMap
std::map< std::string, Ice::ValueFactoryPtr > ObjectFactoryMap
Definition: FactoryCollectionBase.h:61
armarx::ScopedLock
Mutex::scoped_lock ScopedLock
Definition: Synchronization.h:132
IceUtil
Definition: Instance.h:21
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FactoryCollectionBase::addToPreregistration
static FactoryCollectionBaseCleanUp addToPreregistration(FactoryCollectionBasePtr factoryCollection)
Definition: FactoryCollectionBase.cpp:41
armarx::FactoryCollectionBase
Definition: FactoryCollectionBase.h:63
Synchronization.h
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
memoryx::operator<<
std::ostream & operator<<(std::ostream &str, SECKeyFrameBasePtr keyframe)
Definition: SECKeyFrame.cpp:61
Entity.h
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::FactoryCollectionBaseCleanUp
Definition: FactoryCollectionBase.h:38
memoryx::Entity
Definition: Entity.h:246
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
memoryx::EntityAttributePtr
IceInternal::Handle< EntityAttribute > EntityAttributePtr
Typedef of EntityAttributePtr as IceInternal::Handle<EntityAttribute> for convenience.
Definition: EntityAttribute.h:39