Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion JSONAdapterInterface/IJSONValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <memory>
#include <vector>


namespace systelab { namespace json {

enum Type
Expand All @@ -22,7 +21,13 @@ namespace systelab { namespace json {

class IJSONValue
{
template <typename Ref_> class ArrayIterator_;

public:

using ArrayIterator = ArrayIterator_<IJSONValue&>;
using ArrayConstIterator = ArrayIterator_<const IJSONValue&>;

virtual ~IJSONValue() {};

virtual Type getType() const = 0;
Expand Down Expand Up @@ -69,6 +74,11 @@ namespace systelab { namespace json {
// Only for array values
virtual unsigned int getArrayValueCount() const = 0;
virtual IJSONValue& getArrayValue(unsigned int) const = 0;

virtual ArrayIterator begin() = 0;
virtual ArrayIterator end() = 0;
virtual ArrayConstIterator begin() const = 0;
virtual ArrayConstIterator end() const = 0;

virtual void addArrayValue(std::unique_ptr<IJSONValue>) = 0;
virtual void clearArray() = 0;
Expand All @@ -80,6 +90,41 @@ namespace systelab { namespace json {
// Factory methods
virtual std::unique_ptr<IJSONValue> buildValue(Type) const = 0;
virtual std::unique_ptr<IJSONDocument> buildDocument() const = 0;

private:

// Array iterator for range-loop
template <typename Ref_>
class ArrayIterator_
{
public:

~ArrayIterator_() = default;

ArrayIterator_() = delete;

ArrayIterator_(const IJSONValue& value, int distance) : pVal_(&value), distance_(distance) {};

Ref_ operator*() const
{
return (Ref_)pVal_->getArrayValue(distance_);
}

void operator++()
{
++distance_;
}

bool operator!=(const ArrayIterator_<Ref_>& it)
{
return distance_ != it.distance_;
}

private:

const IJSONValue* pVal_;
int distance_;
};
};

}}
5 changes: 5 additions & 0 deletions JSONAdapterTestUtilities/Mocks/MockJSONValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ namespace systelab { namespace json { namespace test_utility {

MOCK_CONST_METHOD0(getArrayValueCount, unsigned int());
MOCK_CONST_METHOD1(getArrayValue, IJSONValue&(unsigned int));

MOCK_METHOD0(begin, ArrayIterator());
MOCK_METHOD0(end, ArrayIterator());
MOCK_CONST_METHOD0(begin, ArrayConstIterator());
MOCK_CONST_METHOD0(end, ArrayConstIterator());

MOCK_CONST_METHOD1(addArrayValueProxy, void(IJSONValue*));
void addArrayValue(std::unique_ptr<IJSONValue> value)
Expand Down