Skip to content

Commit 992e27f

Browse files
author
a-pavlov
committed
Add trivial to_string
1 parent 430a204 commit 992e27f

5 files changed

Lines changed: 38 additions & 3 deletions

File tree

client_demo/netlicensing_client_demo.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ int main(int argc, char* argv[]) {
4242
std::list<netlicensing::ValidationResult> vres = netlicensing::validate(ctx, license_number);
4343
std::cout << "got validation results: " << vres.size() << std::endl;
4444
for (auto val_res : vres) {
45-
std::cout << "lic model: {" << val_res.licensing_model_ << "} prod mod name {" << val_res.product_module_name_ << "}"
46-
<< " properties size{" << val_res.properties_.size() << "}\n";
45+
std::cout << val_res.to_string() << std::endl;
46+
//std::cout << "lic model: {" << val_res.licensing_model_ << "} prod mod name {" << val_res.product_module_name_ << "}"
47+
// << " properties size{" << val_res.properties_.size() << "}\n";
4748
}
4849
}
4950
}

include/netlicensing/entity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct NamedList {
2626

2727
template<class T>
2828
struct RecursiveList : public NamedList {
29-
std::string name_;
3029
std::list<std::shared_ptr<RecursiveList<T> > > nested_lists_;
3130

3231
void add_list(std::shared_ptr<RecursiveList<T> > ptr) {
@@ -70,6 +69,7 @@ class Entity {
7069
public:
7170
bool add_property(const std::string& key, const std::string& value);
7271
std::string get_property(const std::string& key) const;
72+
std::string to_string() const;
7373
};
7474

7575
struct Info {

include/netlicensing/validation_result.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ struct ValidationProperty : public RecursiveList<ValidationProperty> {
1414
if (RecursiveList<ValidationProperty>::add_property(name, value)) return;
1515
values.add_property(name, value);
1616
}
17+
18+
std::string to_string() const;
1719
};
1820

1921

@@ -29,6 +31,7 @@ struct ValidationResult {
2931
std::list<std::shared_ptr<ValidationProperty> > properties_;
3032
void add_property(const std::string& name, const std::string& value);
3133
void add_list(std::shared_ptr<PropertyType> ptr);
34+
std::string to_string() const;
3235
};
3336

3437
}

src/entity.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "netlicensing/entity.h"
2+
#include <sstream>
23

34
namespace netlicensing {
45

@@ -13,6 +14,15 @@ std::string Entity::get_property(const std::string& key) const {
1314
return "";
1415
}
1516

17+
std::string Entity::to_string() const {
18+
std::stringstream ss;
19+
for (auto kv : user_defined_properties_) {
20+
ss << kv.first << "{" << kv.second << "} ";
21+
}
22+
23+
return ss.str();
24+
}
25+
1626
void Info::add_property(const std::string& name, const std::string& value) {
1727
if (name == "value") value_ = value;
1828
else if (name == "id") id_ = value;

src/validation_result.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#include "netlicensing/validation_result.h"
2+
#include <sstream>
23

34
namespace netlicensing {
45

6+
std::string ValidationProperty::to_string() const {
7+
std::stringstream ss;
8+
ss << "ProductModule <" << name_ << "\n";
9+
ss << values.to_string();
10+
//for (auto nested : nested_lists_) {
11+
// ss << nested->nested_lists_.;
12+
//}
13+
ss << ">\n";
14+
return ss.str();
15+
}
16+
517
void ValidationResult::add_property(const std::string& name, const std::string& value) {
618
if (name == "productModuleNumber") product_module_number_ = value;
719
else if (name == "productModuleName") product_module_name_ = value;
@@ -12,4 +24,13 @@ void ValidationResult::add_list(std::shared_ptr<PropertyType> ptr) {
1224
properties_.push_back(ptr);
1325
}
1426

27+
std::string ValidationResult::to_string() const {
28+
std::stringstream ss;
29+
for (auto vp : properties_) {
30+
ss << vp->to_string();
31+
}
32+
33+
return ss.str();
34+
}
35+
1536
}

0 commit comments

Comments
 (0)