Commit 08b86819 authored by legoc's avatar legoc
Browse files

(split) Removed optional use

parent 797008cd
...@@ -19,10 +19,11 @@ ...@@ -19,10 +19,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <optional>
namespace cameo { namespace cameo {
const int Null = 0;
std::vector<std::string> split(const std::string& str, char c); std::vector<std::string> split(const std::string& str, char c);
class Endpoint { class Endpoint {
...@@ -30,6 +31,7 @@ class Endpoint { ...@@ -30,6 +31,7 @@ class Endpoint {
public: public:
Endpoint(const std::string& protocol, const std::string& address, int port); Endpoint(const std::string& protocol, const std::string& address, int port);
Endpoint(const std::string& address, int port); Endpoint(const std::string& address, int port);
Endpoint();
const std::string& getProtocol() const; const std::string& getProtocol() const;
const std::string& getAddress() const; const std::string& getAddress() const;
...@@ -50,16 +52,17 @@ class ApplicationIdentity { ...@@ -50,16 +52,17 @@ class ApplicationIdentity {
public: public:
ApplicationIdentity(const std::string& name, int id, const Endpoint& endpoint); ApplicationIdentity(const std::string& name, int id, const Endpoint& endpoint);
ApplicationIdentity(const std::string& name, const Endpoint& endpoint); ApplicationIdentity(const std::string& name, const Endpoint& endpoint);
ApplicationIdentity();
const std::string& getName() const; const std::string& getName() const;
const std::optional<int>& getId() const; int getId() const;
const Endpoint& getEndpoint() const; const Endpoint& getEndpoint() const;
std::string toJSONString() const; std::string toJSONString() const;
private: private:
std::string m_name; std::string m_name;
std::optional<int> m_id; int m_id;
Endpoint m_endpoint; Endpoint m_endpoint;
}; };
...@@ -70,13 +73,15 @@ public: ...@@ -70,13 +73,15 @@ public:
ApplicationWithStarterIdentity(const ApplicationIdentity& application); ApplicationWithStarterIdentity(const ApplicationIdentity& application);
const ApplicationIdentity& getApplication() const; const ApplicationIdentity& getApplication() const;
const std::optional<ApplicationIdentity>& getStarter() const; bool hasStarter() const;
const ApplicationIdentity& getStarter() const;
std::string toJSONString() const; std::string toJSONString() const;
private: private:
ApplicationIdentity m_application; ApplicationIdentity m_application;
std::optional<ApplicationIdentity> m_starter; bool m_hasStarter;
ApplicationIdentity m_starter;
}; };
} }
......
...@@ -52,6 +52,10 @@ Endpoint::Endpoint(const std::string& address, int port) { ...@@ -52,6 +52,10 @@ Endpoint::Endpoint(const std::string& address, int port) {
m_port = port; m_port = port;
} }
Endpoint::Endpoint() :
m_port(0) {
}
const std::string& Endpoint::getProtocol() const { const std::string& Endpoint::getProtocol() const {
return m_protocol; return m_protocol;
} }
...@@ -108,14 +112,19 @@ ApplicationIdentity::ApplicationIdentity(const std::string& name, int id, const ...@@ -108,14 +112,19 @@ ApplicationIdentity::ApplicationIdentity(const std::string& name, int id, const
ApplicationIdentity::ApplicationIdentity(const std::string& name, const Endpoint& endpoint) : ApplicationIdentity::ApplicationIdentity(const std::string& name, const Endpoint& endpoint) :
m_name(name), m_name(name),
m_id(Null),
m_endpoint(endpoint) { m_endpoint(endpoint) {
} }
ApplicationIdentity::ApplicationIdentity() :
m_id(Null) {
}
const std::string& ApplicationIdentity::getName() const { const std::string& ApplicationIdentity::getName() const {
return m_name; return m_name;
} }
const std::optional<int>& ApplicationIdentity::getId() const { int ApplicationIdentity::getId() const {
return m_id; return m_id;
} }
...@@ -130,9 +139,9 @@ std::string ApplicationIdentity::toJSONString() const { ...@@ -130,9 +139,9 @@ std::string ApplicationIdentity::toJSONString() const {
jsonObject.pushKey(message::ApplicationIdentity::NAME); jsonObject.pushKey(message::ApplicationIdentity::NAME);
jsonObject.pushString(m_name); jsonObject.pushString(m_name);
if (m_id.has_value()) { if (m_id != Null) {
jsonObject.pushKey(message::ApplicationIdentity::ID); jsonObject.pushKey(message::ApplicationIdentity::ID);
jsonObject.pushInt(m_id.value()); jsonObject.pushInt(m_id);
} }
jsonObject.pushKey(message::ApplicationIdentity::SERVER); jsonObject.pushKey(message::ApplicationIdentity::SERVER);
...@@ -143,18 +152,24 @@ std::string ApplicationIdentity::toJSONString() const { ...@@ -143,18 +152,24 @@ std::string ApplicationIdentity::toJSONString() const {
ApplicationWithStarterIdentity::ApplicationWithStarterIdentity(const ApplicationIdentity& application, const ApplicationIdentity& starter) : ApplicationWithStarterIdentity::ApplicationWithStarterIdentity(const ApplicationIdentity& application, const ApplicationIdentity& starter) :
m_application(application), m_application(application),
m_hasStarter(true),
m_starter(starter) { m_starter(starter) {
} }
ApplicationWithStarterIdentity::ApplicationWithStarterIdentity(const ApplicationIdentity& application) : ApplicationWithStarterIdentity::ApplicationWithStarterIdentity(const ApplicationIdentity& application) :
m_application(application) { m_application(application),
m_hasStarter(false) {
} }
const ApplicationIdentity& ApplicationWithStarterIdentity::getApplication() const { const ApplicationIdentity& ApplicationWithStarterIdentity::getApplication() const {
return m_application; return m_application;
} }
const std::optional<ApplicationIdentity>& ApplicationWithStarterIdentity::getStarter() const { bool ApplicationWithStarterIdentity::hasStarter() const {
return m_hasStarter;
}
const ApplicationIdentity& ApplicationWithStarterIdentity::getStarter() const {
return m_starter; return m_starter;
} }
...@@ -165,26 +180,26 @@ std::string ApplicationWithStarterIdentity::toJSONString() const { ...@@ -165,26 +180,26 @@ std::string ApplicationWithStarterIdentity::toJSONString() const {
jsonObject.pushKey(message::ApplicationIdentity::NAME); jsonObject.pushKey(message::ApplicationIdentity::NAME);
jsonObject.pushString(m_application.getName()); jsonObject.pushString(m_application.getName());
if (m_application.getId().has_value()) { if (m_application.getId() != Null) {
jsonObject.pushKey(message::ApplicationIdentity::ID); jsonObject.pushKey(message::ApplicationIdentity::ID);
jsonObject.pushInt(m_application.getId().value()); jsonObject.pushInt(m_application.getId());
} }
jsonObject.pushKey(message::ApplicationIdentity::SERVER); jsonObject.pushKey(message::ApplicationIdentity::SERVER);
jsonObject.pushString(m_application.getEndpoint().toString()); jsonObject.pushString(m_application.getEndpoint().toString());
if (m_starter.has_value()) { if (m_hasStarter) {
jsonObject.pushKey(message::ApplicationIdentity::STARTER); jsonObject.pushKey(message::ApplicationIdentity::STARTER);
jsonObject.startObject(); jsonObject.startObject();
jsonObject.pushKey(message::ApplicationIdentity::NAME); jsonObject.pushKey(message::ApplicationIdentity::NAME);
jsonObject.pushString(m_starter.value().getName()); jsonObject.pushString(m_starter.getName());
jsonObject.pushKey(message::ApplicationIdentity::ID); jsonObject.pushKey(message::ApplicationIdentity::ID);
jsonObject.pushInt(m_starter.value().getId().value()); jsonObject.pushInt(m_starter.getId());
jsonObject.pushKey(message::ApplicationIdentity::SERVER); jsonObject.pushKey(message::ApplicationIdentity::SERVER);
jsonObject.pushString(m_starter.value().getEndpoint().toString()); jsonObject.pushString(m_starter.getEndpoint().toString());
jsonObject.endObject(); jsonObject.endObject();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment