refactoring: remove unused parameters and "using namespace std" 30/201030/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 7 Mar 2019 08:17:29 +0000 (09:17 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 7 Mar 2019 14:22:41 +0000 (15:22 +0100)
Change-Id: I886c7dfd075fce52bfa5a8d1e7bf6d9aeb301ec9

src/internal/serializer.cpp
src/internal/serializer.hpp
src/stest_load_perf.cpp
src/stest_performance.cpp

index 1815d29..b75ecf3 100644 (file)
@@ -8,25 +8,23 @@
 #include "include/flatbuffers/flatbuffers.h"
 #include "include/fb_generated.h"
 
-using namespace std;
-
 namespace ldp_xml_parser {
 
-map<Decision, FB::Decision> decisions_map {
+std::map<Decision, FB::Decision> decisions_map {
        { Decision::ANY, FB::Decision_ANY },
        { Decision::DENY, FB::Decision_DENY },
        { Decision::ALLOW, FB::Decision_ALLOW },
        { Decision::CHECK, FB::Decision_CHECK }
 };
 
-map<BusAccessType, FB::BusAccessType> bus_access_map {
+std::map<BusAccessType, FB::BusAccessType> bus_access_map {
        { BusAccessType::USER, FB::BusAccessType_USER },
        { BusAccessType::GROUP, FB::BusAccessType_GROUP },
        { BusAccessType::ALL_USERS, FB::BusAccessType_ALL_USERS },
        { BusAccessType::ALL_GROUPS, FB::BusAccessType_ALL_GROUPS },
 };
 
-map<MessageType, FB::MessageType> message_type_map {
+std::map<MessageType, FB::MessageType> message_type_map {
        { MessageType::ANY, FB::MessageType_ANY },
        { MessageType::METHOD_CALL, FB::MessageType_METHOD_CALL },
        { MessageType::METHOD_RETURN, FB::MessageType_METHOD_RETURN },
@@ -109,14 +107,14 @@ uint8_t* Serializer::serialize(const std::string config_path, size_t &size) {
        ldp_xml::StorageBackendXML xmlStorage;
 
        if (!xmlStorage.init(config_path.c_str())) {
-               cout << "internal_init error" << endl;
+               std::cout << "internal_init error" << std::endl;
                return nullptr;
        }
 
        return serialize(xmlStorage, size);
 }
 
-void Serializer::serialize(const std::string config_path, ostream &output) {
+void Serializer::serialize(const std::string config_path, std::ostream &output) {
        size_t size;
        uint8_t *buf = serialize(config_path, size);
 
@@ -150,7 +148,7 @@ FbOff<FB::PolicyOwn> Serializer::serialize_tree(const OwnershipTree &tree) {
        return policy;
 }
 
-FbOff<FB::PolicyOwnNode> Serializer::serialize_tree(const shared_ptr<TreeNode> &node) {
+FbOff<FB::PolicyOwnNode> Serializer::serialize_tree(const std::shared_ptr<TreeNode> &node) {
        auto prefix_decision_item = serialize_decision(node->getOwnPrefixDecisionItem());
        auto decision_item = serialize_decision(node->getOwnDecisionItem());
 
@@ -200,25 +198,13 @@ auto Serializer::serialize_item(const P &item) -> FbOff<typename type_helper<T>:
 }
 
 template <typename T>
-auto Serializer::serialize_policy(const T &policy,
-                                 const std::vector<FbOff<typename type_helper<T>::item>> items)
+auto Serializer::serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
                                    -> FbOff<typename type_helper<T>::policy> {
-       (void)policy;
        auto create_policy = get_create_policy<T>();
        return create_policy(m_builder, m_builder.CreateVector(items));
 }
 
 template <>
-auto Serializer::serialize_policy(const PolicyAccess &policy,
-                                 const std::vector<FbOff<FB::ItemAccess>> items)
-                                   -> FbOff<FB::PolicyAccess> {
-       (void)policy;
-       auto create_policy = get_create_policy<PolicyAccess>();
-       return create_policy(m_builder,
-                            m_builder.CreateVector(items));
-}
-
-template <>
 auto Serializer::serialize_policy(const PolicyOwn &policy)
                                    -> FbOff<FB::PolicyOwn> {
        return serialize_tree(policy.getTree());
@@ -232,7 +218,7 @@ auto Serializer::serialize_policy(const T &policy) -> FbOff<typename type_helper
                items.push_back(serialize_item<T>(item));
        }
 
-       return serialize_policy(policy, items);
+       return serialize_policy<T>(items);
 }
 
 template <typename T, typename P>
index f8a35c6..57f13b7 100644 (file)
@@ -11,8 +11,6 @@
 #include "storage_backend_xml.hpp"
 #include "policy_containers.hpp"
 
-using namespace std;
-
 namespace ldp_xml_parser
 {
     enum class SetType : uint8_t {
@@ -43,7 +41,7 @@ namespace ldp_xml_parser
        auto get_create_item() -> decltype(type_helper<T>::create_item);
 
        FbOff<FB::PolicyOwn> serialize_tree(const OwnershipTree &tree);
-       FbOff<FB::PolicyOwnNode> serialize_tree(const shared_ptr<TreeNode> &node);
+       FbOff<FB::PolicyOwnNode> serialize_tree(const std::shared_ptr<TreeNode> &node);
        FbOff<FB::DecisionItem> serialize_decision(const DecisionItem &item);
 
        template <typename T, typename P>
@@ -53,8 +51,7 @@ namespace ldp_xml_parser
        auto serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy>;
 
        template <typename T>
-       auto serialize_policy(const T &policy,
-                             const std::vector<FbOff<typename type_helper<T>::item>> items)
+       auto serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
                                -> FbOff<typename type_helper<T>::policy>;
 
        template <typename T, typename P>
@@ -71,7 +68,7 @@ namespace ldp_xml_parser
     public:
        uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
        uint8_t *serialize(const std::string config_path, size_t &size);
-       void serialize(const std::string config_path, ostream &output);
+       void serialize(const std::string config_path, std::ostream &output);
        friend class SerializerTests;
     };
 }
index 70208ca..2794a15 100644 (file)
@@ -59,29 +59,29 @@ bool run_fb(const char *conf_file) {
 void run_tests(const char *conf_file, const char *conf_bin, size_t c, Choice ch) {
        if (ch == Choice::ALL || ch == Choice::XML) {
                if (!measure([&conf_file, c]() { return run_xml(conf_file); }, c, "XML")) {
-                       cout << "ERROR" << endl;
+                       std::cout << "ERROR" << std::endl;
                }
        }
        if (ch == Choice::ALL || ch == Choice::FB) {
                if (!measure([&conf_bin, c]() { return run_fb(conf_bin); }, c, "FB")) {
-                       cout << "ERROR" << endl;
+                       std::cout << "ERROR" << std::endl;
                }
        }
        if (ch == Choice::ALL || ch == Choice::XMLplusFB)
                if (!measure([&conf_file, c]() { return run_xml_plus_fb(conf_file); }, c, "FB after XML")) {
-                       cout << "ERROR" << endl;
+                       std::cout << "ERROR" << std::endl;
                }
 }
 
 void print_help(const char *name) {
-       cout << endl;
-       cout << "usage: " << name << " {-f <config_bin>|-x|-d|-a <config_bin>} {--system|--session|-c <config_xml>} <count>" << endl;
-       cout << endl;
-       cout << "       -f <config_bin> - Flatbuffers" << endl;
-       cout << "       -x              - XML" << endl;
-       cout << "       -d              - FB after XML" << endl;
-       cout << "       -a <config_bin> - All tests" << endl;
-       cout << endl;
+       std::cout << std::endl;
+       std::cout << "usage: " << name << " {-f <config_bin>|-x|-d|-a <config_bin>} {--system|--session|-c <config_xml>} <count>" << std::endl;
+       std::cout << std::endl;
+       std::cout << "       -f <config_bin> - Flatbuffers" << std::endl;
+       std::cout << "       -x              - XML" << std::endl;
+       std::cout << "       -d              - FB after XML" << std::endl;
+       std::cout << "       -a <config_bin> - All tests" << std::endl;
+       std::cout << std::endl;
 }
 
 static const struct option options[] {
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
        }
 
        if (optind < argc) {
-               count = stoi(argv[optind]);
+               count = std::stoi(argv[optind]);
        } else {
                print_help(argv[0]);
                return 1;
index f37b7ad..a98f139 100644 (file)
@@ -218,13 +218,13 @@ void run_tests(const char *conf_file, size_t c, Choice ch) {
 }
 
 void print_help(const char *name) {
-       cout << endl;
-       cout << "usage: " << name << " {-f|-x|-a} {--system|--session|-c <config_xml>} <count>" << endl;
-       cout << endl;
-       cout << "       -f - Flatbuffers" << endl;
-       cout << "       -x - XML" << endl;
-       cout << "       -a - Flatbuffers and XML" << endl;
-       cout << endl;
+       std::cout << std::endl;
+       std::cout << "usage: " << name << " {-f|-x|-a} {--system|--session|-c <config_xml>} <count>" << std::endl;
+       std::cout << std::endl;
+       std::cout << "       -f - Flatbuffers" << std::endl;
+       std::cout << "       -x - XML" << std::endl;
+       std::cout << "       -a - Flatbuffers and XML" << std::endl;
+       std::cout << std::endl;
 }
 
 static const struct option options[] {
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
        }
 
        if (optind < argc) {
-               count = stoi(argv[optind]);
+               count = std::stoi(argv[optind]);
        } else {
                print_help(argv[0]);
                return 1;