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);
    };
    };
    VirtualRobot headers.
  • 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
    std::ostream & operator<<(std::ostream &strm, const AbstractInterface &a)
    constexpr T c
    Entity is the superclass for all MemoryX memory chunks.
    Definition Entity.h:246
  • 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));
    }
    }
    The Variant class is described here: Variants.
    Definition Variant.h:224
    Mutex::scoped_lock ScopedLock
    This file offers overloads of toIce() and fromIce() functions for STL container types.
  • add files to a library SOURCES/HEADERS variables in respective CMakeLists.txt