Skip to content

Commit

Permalink
Merge branch 'fix/shared_model-query_container' into feature/shared_m…
Browse files Browse the repository at this point in the history
…odel
  • Loading branch information
muratovv authored and lebdron committed Dec 19, 2017
2 parents 1cd8134 + 77e3ef3 commit 76cb23b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
28 changes: 25 additions & 3 deletions shared_model/interfaces/queries/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "interfaces/signable.hpp"
#include "interfaces/visitor_apply_for_all.hpp"
#include "model/query.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
Expand Down Expand Up @@ -77,17 +78,38 @@ namespace shared_model {
* system queries plus 1. Required for preventing replay attacks.
* @return attached query counter
*/
virtual const QueryCounterType &queryCounter() = 0;
virtual const QueryCounterType &queryCounter() const = 0;

// ------------------------| Primitive override |-------------------------

std::string toString() const override {
return boost::apply_visitor(detail::ToStringVisitor(), get());
return detail::PrettyStringBuilder()
.init("Query")
.append("creatorId", creatorAccountId())
.append("queryCounter", std::to_string(queryCounter()))
.append(Signable::toString())
.append(boost::apply_visitor(detail::ToStringVisitor(), get()))
.finalize();
}

OldModelType *makeOldModel() const override {
return boost::apply_visitor(
auto old_model = boost::apply_visitor(
detail::OldModelCreatorVisitor<OldModelType *>(), get());
old_model->creator_account_id = creatorAccountId();
old_model->query_counter = queryCounter();
// signature related
old_model->created_ts = createdTime();
std::for_each(signatures().begin(),
signatures().end(),
[&old_model](auto &signature_wrapper) {
// for_each cycle will assign last signature for old
// model. Also, if in new model absence at least one
// signature, this part will be worked correctly.
auto old_sig = signature_wrapper->makeOldModel();
old_model->signature = *old_sig;
delete old_sig;
});
return old_model;
}

bool operator==(const ModelType &rhs) const override {
Expand Down
22 changes: 22 additions & 0 deletions shared_model/interfaces/signable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "interfaces/common_objects/signature.hpp"
#include "interfaces/hashable.hpp"
#include "interfaces/polymorphic_wrapper.hpp"
#include "utils/string_builder.hpp"

namespace shared_model {
namespace interface {
Expand Down Expand Up @@ -88,6 +89,27 @@ namespace shared_model {
* @return time of creation
*/
virtual const TimestampType &createdTime() const = 0;

/**
* Provides comparison based on equality of objects and signatures.
* @param rhs - another model object
* @return true, if objects totally equal
*/
virtual bool equals(const Model &rhs) const {
return *this == rhs and this->signatures() == rhs.signatures()
and this->createdTime() == rhs.createdTime();
}

// ------------------------| Primitive override |-------------------------

std::string toString() const override {
return detail::PrettyStringBuilder()
.init("Signable")
.append("created_time", std::to_string(createdTime()))
.appendAll(signatures(),
[](auto &signature) { return signature->toString(); })
.finalize();
}
};

} // namespace interface
Expand Down

0 comments on commit 76cb23b

Please sign in to comment.