Browse Source

Add key value types

Patrick-Christopher Mattulat 3 years ago
parent
commit
978a7b3a7a
3 changed files with 33 additions and 13 deletions
  1. 8 8
      include/ls_std/io/kv/KVPair.hpp
  2. 20 0
      include/ls_std/io/kv/KVTypes.hpp
  3. 5 5
      source/ls_std/io/kv/KVPair.cpp

+ 8 - 8
include/ls_std/io/kv/KVPair.hpp

@@ -11,25 +11,25 @@
 #define LS_STD_KV_PAIR_HPP
 
 #include <ls_std/base/Class.hpp>
-#include <string>
+#include "KVTypes.hpp"
 
 namespace ls_std {
   class KVPair : public ls_std::Class {
     public:
 
-      explicit KVPair(const std::string& _key, std::string _value);
+      explicit KVPair(const ls_std::kv_key& _key, ls_std::kv_value _value);
       ~KVPair() override = default;
 
-      std::string getKey();
-      std::string getValue();
-      void setValue(const std::string& _value);
+      ls_std::kv_key getKey();
+      ls_std::kv_value getValue();
+      void setValue(const ls_std::kv_value& _value);
 
     private:
 
-      std::string key {};
-      std::string value {};
+      ls_std::kv_key key {};
+      ls_std::kv_value value {};
 
-      void _assignKey(const std::string& _key);
+      void _assignKey(const ls_std::kv_key& _key);
   };
 }
 

+ 20 - 0
include/ls_std/io/kv/KVTypes.hpp

@@ -0,0 +1,20 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-12-25
+ * Changed:         2020-12-25
+ *
+ * */
+
+#ifndef LS_STD_KV_TYPES_HPP
+#define LS_STD_KV_TYPES_HPP
+
+#include <string>
+
+namespace ls_std {
+  using kv_key    = std::string;
+  using kv_value  = std::string;
+}
+
+#endif

+ 5 - 5
source/ls_std/io/kv/KVPair.cpp

@@ -10,28 +10,28 @@
 #include <ls_std/io/kv/KVPair.hpp>
 #include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::KVPair::KVPair(const std::string& _key, std::string _value) : ls_std::Class("KVPair"),
+ls_std::KVPair::KVPair(const ls_std::kv_key& _key, ls_std::kv_value _value) : ls_std::Class("KVPair"),
 value(std::move(_value))
 {
   this->_assignKey(_key);
 }
 
-std::string ls_std::KVPair::getKey()
+ls_std::kv_key ls_std::KVPair::getKey()
 {
   return this->key;
 }
 
-std::string ls_std::KVPair::getValue()
+ls_std::kv_value ls_std::KVPair::getValue()
 {
   return this->value;
 }
 
-void ls_std::KVPair::setValue(const std::string &_value)
+void ls_std::KVPair::setValue(const ls_std::kv_value &_value)
 {
   this->value = _value;
 }
 
-void ls_std::KVPair::_assignKey(const std::string &_key)
+void ls_std::KVPair::_assignKey(const ls_std::kv_key &_key)
 {
   if(_key.empty()) {
     throw ls_std::IllegalArgumentException {};