#pragma once #include #include #include #include "../../core/Defines.h" #include "../../core/Serializer.h" // Pool builder class that can be used to build a pool for a specific kind of tree. Constructor should indicate the tree type. template class BasePoolBuilder { public: virtual ~BasePoolBuilder() {} virtual size_t GetPoolSize(const T* tree) = 0; virtual bool BuildPool(const T* tree, std::vector& pool) = 0; virtual bool VerifyPool(std::vector& pool, const unsigned8& depth) const = 0; virtual std::string GetFullFileName(const std::string& fileName) const = 0; virtual bool ReadPool(const std::string& fileName, std::vector& pool) const { std::string binFileName = GetFullFileName(fileName); std::ifstream nodePoolInFile(binFileName, std::ios::binary); if (nodePoolInFile.good()) { // Destroy whole current node pool Serializer, unsigned64>::Deserialize(pool, nodePoolInFile); nodePoolInFile.close(); return true; } return false; } bool WritePool(const std::string& fileName, const std::vector& pool) const { std::string binFileName = GetFullFileName(fileName); if (!pool.empty()) { std::ofstream nodePoolOutFile(binFileName, std::ios::binary); Serializer, unsigned64>::Serialize(pool, nodePoolOutFile); nodePoolOutFile.close(); return true; } return false; } bool BuildOrReadPool(const T* tree, const std::string& fileName, std::vector& pool) { if (ReadPool(fileName, pool)) return true; bool res = BuildPool(tree, pool); if (res) WritePool(fileName, pool); return res; } bool VerifyCachedPool(const std::string& fileName, const unsigned8& depth) const { std::vector pool; if (ReadPool(fileName, pool)) return VerifyPool(pool, depth); return false; } };