refactoring: extract common file operations to Serializer 84/246284/2
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 27 Oct 2020 09:58:05 +0000 (10:58 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 30 Oct 2020 11:16:57 +0000 (12:16 +0100)
Change-Id: I87e8dd9daa91a35c2748001fba71178d608d2024

Makefile.am
configure.ac
src/internal/serializer.cpp [new file with mode: 0644]
src/internal/serializer.hpp
src/internal/serializer_flatbuffers.cpp
src/internal/serializer_flatbuffers.hpp

index b52237d..0c88727 100644 (file)
@@ -62,6 +62,7 @@ COMMON_SRC =\
        src/internal/own_tree.cpp \
        src/internal/xml_parser.cpp \
        src/internal/tslog.cpp \
+       src/internal/serializer.cpp \
        src/internal/serializer_flatbuffers.cpp \
        src/internal/print_content.cpp \
        src/internal/storage_backend_flatbuffers.cpp \
index febecd2..9a69a05 100644 (file)
@@ -84,7 +84,7 @@ my_CXXFLAGS="\
 -Wall \
 -Wextra \
 -Werror \
--std=c++11 \
+-std=c++14 \
 "
 
 AC_SUBST([my_CXXFLAGS])
diff --git a/src/internal/serializer.cpp b/src/internal/serializer.cpp
new file mode 100644 (file)
index 0000000..f965045
--- /dev/null
@@ -0,0 +1,47 @@
+/*  MIT License
+ *
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include "serializer.hpp"
+#include "storage_backend_xml.hpp"
+#include "tslog.hpp"
+#include <iostream>
+
+using namespace ldp_serializer;
+
+const uint8_t *Serializer::serialize(const std::string &config_path, size_t &size) {
+       tslog::init(tslog::ldp_log_level::DEFAULT);
+       ldp_xml::StorageBackendXML xmlStorage;
+
+       if (!xmlStorage.init(config_path.c_str())) {
+               std::cout << "xmlStorage init error" << std::endl;
+               return nullptr;
+       }
+
+       return serialize(xmlStorage, size);
+}
+const uint8_t *Serializer::serialize(const std::string &config_path, std::ostream &output) {
+       size_t size = 0;
+       auto buf = serialize(config_path, size);
+
+       output.write(reinterpret_cast<const char *>(buf), size);
+       return buf;
+}
index dfa9d7a..34c8c9f 100644 (file)
  * THE SOFTWARE. */
 
 #include "serializer_flatbuffers.hpp"
+#include <iostream>
+#include <string>
+
+namespace ldp_xml {
+class StorageBackendXML;
+};
+
+namespace ldp_serializer
+{
+
+class Serializer {
+       SerializerFlatbuffers impl;
+public:
+       auto serialize(const ldp_xml::StorageBackendXML &db, size_t &size) {
+               return impl.serialize(db, size);
+       }
+       const uint8_t *serialize(const std::string &config_path, size_t &size);
+       const uint8_t *serialize(const std::string &config_path, std::ostream &output);
+};
 
-namespace ldp_serializer {
-using Serializer = SerializerFlatbuffers;
 }
index b79558a..dc38275 100644 (file)
@@ -115,26 +115,6 @@ const uint8_t* SerializerFlatbuffers::serialize(const ldp_xml::StorageBackendXML
        return buf;
 }
 
-const uint8_t* SerializerFlatbuffers::serialize(const std::string config_path, size_t &size) {
-       tslog::init(tslog::ldp_log_level::DEFAULT);
-       ldp_xml::StorageBackendXML xmlStorage;
-
-       if (!xmlStorage.init(config_path.c_str())) {
-               std::cout << "xmlStorage init error" << std::endl;
-               return nullptr;
-       }
-
-       return serialize(xmlStorage, size);
-}
-
-const uint8_t *SerializerFlatbuffers::serialize(const std::string config_path, std::ostream &output) {
-       size_t size = 0;
-       auto buf = serialize(config_path, size);
-
-       output.write(reinterpret_cast<const char *>(buf), size);
-       return buf;
-}
-
 template <typename T>
 auto SerializerFlatbuffers::get_create_set() -> decltype(type_helper<T>::create_set) {
        return type_helper<T>::create_set;
index 10f0c12..62847fe 100644 (file)
@@ -76,8 +76,6 @@ namespace ldp_serializer
        public:
                SerializerFlatbuffers() : m_db(nullptr) {}
                const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
-               const uint8_t *serialize(const std::string config_path, size_t &size);
-               const uint8_t *serialize(const std::string config_path, std::ostream &output);
                friend class SerializerTests;
        };
 }