Move bucket separators to PathConfig::StoragePath 18/33518/11
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Mon, 12 Jan 2015 12:45:21 +0000 (13:45 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 24 Feb 2015 15:20:47 +0000 (16:20 +0100)
This patch removes both bucket separators - for fields as well as for
records - from StorageSerializer. To this point they could be accessed
using provided static member functions. This is no longer possible, as
StorageSerializer has to be rewritten using templates.

Change-Id: Ib010bd0b125a1a93da9983d9bdd7b8f75cbbc191

src/common/config/PathConfig.cpp
src/common/config/PathConfig.h
src/cyad/AdminPolicyParser.cpp
src/storage/BucketDeserializer.cpp
src/storage/StorageDeserializer.cpp
src/storage/StorageSerializer.cpp
src/storage/StorageSerializer.h

index 2e2309b..6039622 100644 (file)
@@ -57,8 +57,10 @@ const std::string lockFile(statePath);
 const std::string indexFilename("buckets");
 const std::string guardFilename("guard");
 const std::string checksumFilename("checksum");
-const std::string bucketFilenamePrefix("_");
 const std::string backupFilenameSuffix("~");
+const std::string bucketFilenamePrefix("_");
+const char fieldSeparator(';');
+const char recordSeparator('\n');
 } // namespace StoragePath
 
 namespace PluginPath {
index 0ba109f..8655e95 100644 (file)
@@ -45,8 +45,10 @@ extern const std::string lockFile;
 extern const std::string indexFilename;
 extern const std::string guardFilename;
 extern const std::string checksumFilename;
-extern const std::string bucketFilenamePrefix;
 extern const std::string backupFilenameSuffix;
+extern const std::string bucketFilenamePrefix;
+extern const char fieldSeparator;
+extern const char recordSeparator;
 } // namespace StoragePath
 
 namespace PluginPath {
index 530ca90..4f42a87 100644 (file)
@@ -20,9 +20,9 @@
  * @brief       Parses policies from input stream
  */
 
+#include <config/PathConfig.h>
 #include <exceptions/BucketRecordCorruptedException.h>
 #include <storage/StorageDeserializer.h>
-#include <storage/StorageSerializer.h>
 
 #include "AdminPolicyParser.h"
 
@@ -35,7 +35,7 @@ CynaraAdminPolicies parse(const std::shared_ptr<std::istream> &input,
     CynaraAdminPolicies policies;
 
     auto nextToken = [] (const std::string &line, std::size_t &beginToken) -> std::string  {
-        auto endToken = line.find(StorageSerializer::fieldSeparator(), beginToken);
+        auto endToken = line.find(PathConfig::StoragePath::fieldSeparator, beginToken);
         if (endToken != std::string::npos) {
             auto token = line.substr(beginToken, endToken - beginToken);
             beginToken = endToken + 1;
@@ -57,7 +57,7 @@ CynaraAdminPolicies parse(const std::shared_ptr<std::istream> &input,
 
     for (std::size_t lineNum = 1; !input->eof(); ++lineNum) {
         std::string line;
-        std::getline(*input, line, StorageSerializer::recordSeparator());
+        std::getline(*input, line, PathConfig::StoragePath::recordSeparator);
 
         if (line.empty())
             break;
index 68a3f4e..610e527 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
 #include <string>
 #include <vector>
 
+#include <config/PathConfig.h>
 #include <exceptions/BucketRecordCorruptedException.h>
 #include <types/PolicyCollection.h>
 #include <types/PolicyResult.h>
 #include <types/PolicyType.h>
 
 #include <storage/StorageDeserializer.h>
-#include <storage/StorageSerializer.h>
 
 #include "BucketDeserializer.h"
 
@@ -43,7 +43,7 @@ PolicyCollection BucketDeserializer::loadPolicies(void) {
     // TODO: Get someone smart to do error checking on stream
     for (std::size_t lineNum = 1; !m_inStream->eof(); ++lineNum) {
         std::string line;
-        std::getline(*m_inStream, line, StorageSerializer::recordSeparator());
+        std::getline(*m_inStream, line, PathConfig::StoragePath::recordSeparator);
 
         if (line.empty())
             break;
@@ -67,7 +67,7 @@ PolicyKey BucketDeserializer::parseKey(const std::string &line, std::size_t &beg
     std::array<std::string, 3> keyFeatures;
 
     for (std::size_t tokenNum = 0; tokenNum < keyFeatures.size(); ++tokenNum) {
-        auto endToken = line.find(StorageSerializer::fieldSeparator(), beginToken);
+        auto endToken = line.find(PathConfig::StoragePath::fieldSeparator, beginToken);
         if (endToken != std::string::npos) {
             keyFeatures[tokenNum] = line.substr(beginToken, endToken - beginToken);
             beginToken = endToken + 1;
index 166a406..5d9933e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
 #include <memory>
 #include <string>
 
+#include <config/PathConfig.h>
 #include <exceptions/BucketDeserializationException.h>
 #include <exceptions/BucketRecordCorruptedException.h>
 #include <types/PolicyType.h>
 
 #include <storage/BucketDeserializer.h>
 #include <storage/Buckets.h>
-#include <storage/StorageSerializer.h>
 
 #include "StorageDeserializer.h"
 
@@ -46,7 +46,7 @@ void StorageDeserializer::initBuckets(Buckets &buckets) {
 
     for (std::size_t lineNum = 1; !m_inStream->eof(); ++lineNum) {
         std::string line;
-        std::getline(*m_inStream, line, StorageSerializer::recordSeparator());
+        std::getline(*m_inStream, line, PathConfig::StoragePath::recordSeparator);
 
         if (line.empty())
             break;
@@ -80,7 +80,7 @@ void StorageDeserializer::loadBuckets(Buckets &buckets) {
 
 PolicyBucketId StorageDeserializer::parseBucketId(const std::string &line,
                                                     std::size_t &beginToken) {
-    auto bucketNameEndToken = line.find(StorageSerializer::fieldSeparator(), beginToken);
+    auto bucketNameEndToken = line.find(PathConfig::StoragePath::fieldSeparator, beginToken);
     if (bucketNameEndToken != std::string::npos) {
         auto bucketName = line.substr(beginToken, bucketNameEndToken - beginToken);
         beginToken = bucketNameEndToken + 1;
index 132f2c6..9f701dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -35,9 +35,6 @@
 
 namespace Cynara {
 
-char StorageSerializer::m_fieldSeparator = ';';
-char StorageSerializer::m_recordSeparator = '\n';
-
 StorageSerializer::StorageSerializer(std::shared_ptr<std::ostream> os) : m_outStream(os) {
 }
 
index 8e21f9b..42982b2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
 #include <fstream>
 #include <memory>
 
+#include <config/PathConfig.h>
 #include <types/PolicyBucket.h>
 #include <types/PolicyBucketId.h>
 #include <types/PolicyCollection.h>
@@ -56,13 +57,13 @@ protected:
     inline void dumpFields(const Arg1 &arg1, const Args&... args) {
         dump(arg1);
         if (sizeof...(Args) > 0) {
-            *m_outStream << fieldSeparator();
+            *m_outStream << PathConfig::StoragePath::fieldSeparator;
         }
         dumpFields(args...);
     }
 
     inline void dumpFields(void) {
-        *m_outStream << recordSeparator();
+        *m_outStream << PathConfig::StoragePath::recordSeparator;
     }
 
     void dump(const PolicyKeyFeature &keyFeature);
@@ -72,18 +73,6 @@ protected:
 
 private:
     std::shared_ptr<std::ostream> m_outStream;
-
-    static char m_fieldSeparator;
-    static char m_recordSeparator;
-
-public:
-    static const char &fieldSeparator(void) {
-        return m_fieldSeparator;
-    }
-
-    static const char &recordSeparator(void) {
-        return m_recordSeparator;
-    }
 };
 
 } /* namespace Cynara */