sempr-tk / sempr

SEMPR - Semantic Environment Mapping, Processing and Reasoning
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

added RDFValue::operator == (const T&) #38

Closed niniemann closed 6 years ago

niniemann commented 6 years ago

This fixes #30 as good as possible, I think:

The first part of the issue cannot be resolved so easily, since I have no influence on the the assignment operator of std::string, which accepts different types, so that the compiler does not know which type it should cast our RDFValue to. The solution is to use the template <class T> RDFValue::get() method here (which is not new, but now works due to the removed const):

std::string foo = map["key"]; // no problem (copy ctor)
// foo = map["key"]; // does not work, ambiguous (assignment operator)
foo = map["key"].get<std::string>(); // works (assignment operator) since we explicitly specify the type to cast to

The second part of the issue has to do with comparing values to entries in the RDFPropertyMap. I simply added the template <class T> RDFValue::operator == (const T&) which casts to T and compares the result with the given value. With one exception to correctly compare with const char*.

niniemann commented 6 years ago

Sorry, I messed up. This depends on #37 ! Wait for that one to be merged.

niniemann commented 6 years ago

Maybe we should add the other operators, too, before merging this?

ctieben commented 6 years ago

Which other operators did you mean in detail?

niniemann commented 6 years ago

Comparisons. Less than, less or equal, greater than, greater or equal.

ctieben commented 6 years ago

And yes some more operators sounds helpfully and fits in the context of this PR.

niniemann commented 6 years ago

I've added the other comparison operators, and thought about implementing stuff like incrementation etc., too, but I'm not sure if/how to implement them properly in a generic way. So I'll just leave it as is for now.