Pārlūkot izejas kodu

refactor: remove cxx file as redundant

Sam Jaffe 2 gadi atpakaļ
vecāks
revīzija
e7f35c498d

+ 14 - 1
include/serializer/jsonizer.tpp

@@ -11,15 +11,28 @@
 #include <iostream>
 #include <stdexcept>
 
+#include <expect/expect.hpp>
 #include <json/json.h>
 #include <magic_enum.hpp>
+#include <string_utils/cast.h>
 
 #include <serializer/jsonizer.h>
+#include <serializer/shared_cache.h>
 #include <serializer/strconv.h>
 #include <serializer/traits.h>
-#include <string_utils/cast.h>
 
 namespace serializer {
+
+Jsonizer::Jsonizer() : p_cache(std::make_shared<SharedCache>()) {}
+/**
+ * @brief Construct a jsonizer with an externally owned cache
+ * @param cache A shared_ptr to a data cache. Cannot be null
+ * @throws std::logic_error if cache == nullptr
+ */
+Jsonizer::Jsonizer(std::shared_ptr<SharedCache> cache) : p_cache(cache) {
+  expects(p_cache != nullptr);
+}
+
 template <typename T, size_t... Is>
 Json::Value Jsonizer::to_json(T & value, std::index_sequence<Is...>) const {
   Json::Value json;

+ 13 - 6
include/serializer/shared_cache.h

@@ -15,10 +15,17 @@ class SharedCache {
 public:
   using Key = std::string;
   template <typename T> using Record = std::shared_ptr<T const>;
+  
+protected:
+  struct Impl {
+    virtual ~Impl() = default;
+  };
+
+private:
+  std::unique_ptr<Impl> p_impl = std::make_unique<Impl>();
 
 public:
-  SharedCache();
-  ~SharedCache();
+  SharedCache() = default;
 
   /**
    * @brief Store an object within this cache, returning a pointer to the
@@ -43,9 +50,9 @@ public:
   template <typename T> Record<T> fetch(Key const & key) const {
     throw std::domain_error(typeid(T).name());
   }
-
-private:
-  struct Impl;
-  std::unique_ptr<Impl> p_impl;
+  
+protected:
+  template <typename T>
+  SharedCache(std::unique_ptr<T> ptr) : p_impl(std::move(ptr)) {}
 };
 }

+ 10 - 12
serializer.xcodeproj/project.pbxproj

@@ -10,8 +10,12 @@
 		CD592C0F29C3D932009AC14E /* serializer in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0629C2A5EB009AC14E /* serializer */; settings = {ATTRIBUTES = (Public, ); }; };
 		CD592C2229C3DB79009AC14E /* jsonizer_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD592C2129C3DB79009AC14E /* jsonizer_test.cxx */; };
 		CD592C2729C3DC65009AC14E /* libjsoncpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CD592C2629C3DC65009AC14E /* libjsoncpp.a */; };
-		CD592C4629C3E153009AC14E /* jsonizier.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD592C4329C3E001009AC14E /* jsonizier.cxx */; };
 		CD592C4729C3E1A2009AC14E /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD592C3029C3DC76009AC14E /* GoogleMock.framework */; };
+		CDD4757729C3EEE200BDB829 /* forwards.h in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0B29C2A6C8009AC14E /* forwards.h */; };
+		CDD4757829C3EEE500BDB829 /* jsonizer.h in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0729C2A607009AC14E /* jsonizer.h */; };
+		CDD4757929C3EEEB00BDB829 /* shared_cache.h in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0929C2A63A009AC14E /* shared_cache.h */; };
+		CDD4757A29C3EEEE00BDB829 /* strconv.h in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0A29C2A64C009AC14E /* strconv.h */; };
+		CDD4757B29C3EEF000BDB829 /* traits.h in Headers */ = {isa = PBXBuildFile; fileRef = CD592C0C29C2A707009AC14E /* traits.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -81,7 +85,6 @@
 		CD592C2629C3DC65009AC14E /* libjsoncpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjsoncpp.a; path = ../../../../../../../../opt/local/lib/libjsoncpp.a; sourceTree = "<group>"; };
 		CD592C2829C3DC76009AC14E /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 		CD592C3729C3DC84009AC14E /* string-utils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "string-utils.xcodeproj"; path = "external/string-utils/string-utils.xcodeproj"; sourceTree = "<group>"; };
-		CD592C4329C3E001009AC14E /* jsonizier.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = jsonizier.cxx; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -111,7 +114,6 @@
 				CD592C3729C3DC84009AC14E /* string-utils.xcodeproj */,
 				CD592C0629C2A5EB009AC14E /* serializer */,
 				CD592C0429C2A5E0009AC14E /* include */,
-				CD592C4229C3DFEE009AC14E /* src */,
 				CD592C1229C3DB22009AC14E /* test */,
 				CD592C1829C3DB32009AC14E /* serializer-test */,
 				CD592BFE29C2A5BF009AC14E /* Products */,
@@ -193,14 +195,6 @@
 			name = Products;
 			sourceTree = "<group>";
 		};
-		CD592C4229C3DFEE009AC14E /* src */ = {
-			isa = PBXGroup;
-			children = (
-				CD592C4329C3E001009AC14E /* jsonizier.cxx */,
-			);
-			path = src;
-			sourceTree = "<group>";
-		};
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
@@ -208,7 +202,12 @@
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDD4757729C3EEE200BDB829 /* forwards.h in Headers */,
+				CDD4757B29C3EEF000BDB829 /* traits.h in Headers */,
+				CDD4757829C3EEE500BDB829 /* jsonizer.h in Headers */,
+				CDD4757929C3EEEB00BDB829 /* shared_cache.h in Headers */,
 				CD592C0F29C3D932009AC14E /* serializer in Headers */,
+				CDD4757A29C3EEEE00BDB829 /* strconv.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -365,7 +364,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				CD592C2229C3DB79009AC14E /* jsonizer_test.cxx in Sources */,
-				CD592C4629C3E153009AC14E /* jsonizier.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 0 - 25
src/jsonizier.cxx

@@ -1,25 +0,0 @@
-//
-//  jsonizier.cxx
-//  serializer
-//
-//  Created by Sam Jaffe on 3/16/23.
-//
-
-#include <serializer/jsonizer.h>
-
-#include <expect/expect.hpp>
-
-#include <serializer/shared_cache.h>
-
-
-namespace serializer {
-struct SharedCache::Impl {};
-
-SharedCache::SharedCache() : p_impl(new Impl) {}
-SharedCache::~SharedCache() {}
-
-Jsonizer::Jsonizer() : p_cache(std::make_shared<SharedCache>()) {}
-Jsonizer::Jsonizer(std::shared_ptr<SharedCache> cache) : p_cache(cache) {
-  expects(p_cache != nullptr);
-}
-}