-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reworked RDFEntity interface and added SemanticEntity #37
Changes from 11 commits
ab32f8b
d7bc716
c8c264f
3b69b78
751b1df
b7cd6ae
3950dc8
faf62fe
276ee9a
b75f0a2
372a14c
f6aedda
97cfeb2
4a6d8e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,86 @@ | ||
#ifndef SEMPR_ENTITY_RDFENTITY_H_ | ||
#define SEMPR_ENTITY_RDFENTITY_H_ | ||
#ifndef SEMPR_ENTITY_RDFENTITY_HPP_ | ||
#define SEMPR_ENTITY_RDFENTITY_HPP_ | ||
|
||
#include <odb/core.hxx> | ||
#include <sempr/core/RDF.hpp> | ||
#include <sempr/entity/Entity.hpp> | ||
#include <sempr/entity/Triple.hpp> | ||
|
||
// #include <sempr/core/EventBroker.hpp> | ||
#include <sempr/core/EntityEvent.hpp> | ||
|
||
#include <vector> | ||
|
||
namespace sempr { namespace entity { | ||
|
||
|
||
class TripleIterator_impl { | ||
friend class TripleIterator; | ||
protected: | ||
virtual ~TripleIterator_impl(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange naming with *_impl and it implements nothing its just an interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that I want to return an iterator by value, and not a pointer to an iterator that points to some triples. The latter would force the user to write stuff like I agree that the naming of the actual implementations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'm on it. |
||
|
||
virtual const Triple operator * () const = 0; | ||
virtual void operator ++ () = 0; | ||
virtual bool operator == (const TripleIterator_impl& other) const = 0; | ||
}; | ||
|
||
/** | ||
Custom abstract iterator to hide implementation of the container. | ||
This way a RDFEntity can use a vector or a map or whatever it likes, just by implementing | ||
the TripleIterator_impl. | ||
|
||
This class uses the pimpl-idiom: Every RDFEntity-subtype returns a TripleIterator, but with | ||
different implementations. To create your own implement a subclass of TripleIterator_impl and | ||
pass an instance of it to the ctor of the TripleIterator. | ||
|
||
Although the class is called "[...]Iterator" it not really behaves like one. | ||
Since we cannot assert that every container implementing this actually stores triples which | ||
we could reference, it needs to return triples by value instead. | ||
*/ | ||
class TripleIterator { | ||
TripleIterator_impl* impl_; | ||
public: | ||
TripleIterator(TripleIterator_impl* impl); | ||
~TripleIterator(); | ||
|
||
/** | ||
"read-only" access: Creates a copy of the represented triple. | ||
*/ | ||
const Triple operator * () const; | ||
|
||
TripleIterator& operator ++ (); | ||
bool operator == (const TripleIterator& other) const; | ||
bool operator != (const TripleIterator& other) const; | ||
}; | ||
|
||
|
||
/** | ||
The RDFEntity is the interface for all entities that focus on providing rdf triples. It only | ||
allows iteration over the (constant!) triples, nothing more. This way every module may read the | ||
triples, but only modify them if they know how to exactly. (This was a major problem before, | ||
when RDFPropertyMap inherited RDFVector, so through RDFVector the RDFPropertyMap could become | ||
invalid!) | ||
*/ | ||
#pragma db object | ||
class RDFEntity : public Entity { | ||
SEMPR_ENTITY | ||
public: | ||
using Ptr = std::shared_ptr<RDFEntity>; | ||
// using Event = core::EntityEvent<RDFEntity>; | ||
RDFEntity(); | ||
RDFEntity(const core::IDGenBase*); | ||
virtual ~RDFEntity(){} | ||
virtual ~RDFEntity(){}; | ||
|
||
/** copy the triples into a vector */ | ||
void getTriples(std::vector<Triple>& triples) const; | ||
Triple& getTripleAt(const size_t& index); | ||
bool addTriple(const Triple& triple); | ||
bool removeTriple(const Triple& triple); | ||
void removeTripleAt(const size_t& index); | ||
void clear(); | ||
size_t size() const; | ||
std::vector<Triple>::const_iterator begin() const; | ||
std::vector<Triple>::const_iterator end() const; | ||
|
||
/** iterate the triples */ | ||
virtual TripleIterator begin() const; | ||
virtual TripleIterator end() const; | ||
|
||
protected: | ||
RDFEntity(const core::IDGenBase*); | ||
private: | ||
friend class odb::access; | ||
std::vector<Triple> triples_; | ||
RDFEntity(); | ||
}; | ||
|
||
}} | ||
|
||
#endif /* end of include guard: SEMPR_ENTITY_RDFENTITY_H_ */ | ||
} /* entity */ | ||
|
||
} /* sempr */ | ||
|
||
#endif /* end of include guard: SEMPR_ENTITY_RDFENTITY_HPP_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect such a details description as code documentation not as general in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is well-documented, of course :D. Everything you read here is described in code-comments, too -- this is just a more structured explanation of how stuff works internally that can be read in one go.
Also, it is written beneath the header "Implementation details", so IMHO this is totally fine. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍