BS 0.1.0 File未完善
This commit is contained in:
@@ -74,60 +74,19 @@ namespace Convention
|
||||
}
|
||||
};
|
||||
|
||||
template<template<typename> class ElementPtr = std::shared_ptr>
|
||||
class DependenceModel
|
||||
: public IConvertModel<bool>
|
||||
{
|
||||
private:
|
||||
std::vector<ElementPtr<IConvertable<bool>>> queries;
|
||||
std::vector<IConvertable<bool>*> queries;
|
||||
public:
|
||||
DependenceModel(std::vector<ElementPtr<IConvertable<bool>>> queries) :__init(queries) {}
|
||||
DependenceModel(std::vector<IConvertable<bool>*> queries) :__init(queries) {}
|
||||
|
||||
bool ConvertTo()
|
||||
{
|
||||
for (auto&& query : queries)
|
||||
{
|
||||
if ((*query).ConvertTo() == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
decltype(auto) begin() noexcept
|
||||
{
|
||||
return queries.begin();
|
||||
}
|
||||
|
||||
decltype(auto) end() noexcept
|
||||
{
|
||||
return queries.end();
|
||||
}
|
||||
|
||||
virtual void Load(std::string_view data) override
|
||||
{
|
||||
throw std::runtime_error("NotImplementedException");
|
||||
}
|
||||
|
||||
virtual string Save() override
|
||||
{
|
||||
throw std::runtime_error("NotImplementedException");
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class DependenceModel<ElementTuple>
|
||||
: public IConvertModel<bool>
|
||||
{
|
||||
private:
|
||||
std::vector<IConvertable<bool>> queries;
|
||||
public:
|
||||
DependenceModel(std::vector<IConvertable<bool>> queries) :__init(queries) {}
|
||||
|
||||
bool ConvertTo()
|
||||
{
|
||||
for (auto&& query : queries)
|
||||
{
|
||||
if (query.ConvertTo() == false)
|
||||
if (query->ConvertTo() == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -177,10 +136,13 @@ namespace Convention
|
||||
#pragma region Objects Registered
|
||||
|
||||
private:
|
||||
|
||||
std::map<TypeID, std::vector<std::shared_ptr<IConvertable<bool>>>> ImplTypeQuery;
|
||||
|
||||
std::set<TypeID> RegisterHistory;
|
||||
std::map<TypeID, void*> UncompleteTargets;
|
||||
std::map<TypeID, std::function<void()>> Completer;
|
||||
std::map<TypeID, DependenceModel<>> Dependences;
|
||||
std::map<TypeID, DependenceModel> Dependences;
|
||||
std::map<TypeID, void*> Childs;
|
||||
|
||||
class TypeQuery
|
||||
@@ -247,6 +209,7 @@ namespace Convention
|
||||
{
|
||||
Childs[complete] = UncompleteTargets[complete];
|
||||
UncompleteTargets.erase(complete);
|
||||
ImplTypeQuery.erase(complete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,12 +223,14 @@ namespace Convention
|
||||
RegisterHistory.insert(slot.hash_code());
|
||||
Completer[slot.hash_code()] = completer;
|
||||
UncompleteTargets[slot.hash_code()] = target;
|
||||
std::vector<std::shared_ptr<IConvertable<bool>>> dependenceModel;
|
||||
std::vector<IConvertable<bool>*> dependenceModel;
|
||||
for (auto&& type : dependences)
|
||||
{
|
||||
dependenceModel.push_back(std::make_shared<TypeQuery>(new TypeQuery(slot)));
|
||||
auto cur = std::make_shared<TypeQuery>(new TypeQuery(slot));
|
||||
ImplTypeQuery[slot.hash_code()].push_back(cur);
|
||||
dependenceModel.push_back(cur.get());
|
||||
}
|
||||
Dependences[slot.hash_code()] = DependenceModel<>(dependenceModel);
|
||||
Dependences[slot.hash_code()] = DependenceModel(dependenceModel);
|
||||
std::set<TypeID> buffer;
|
||||
while (InternalRegisteringComplete(buffer))
|
||||
InternalRegisteringUpdate(buffer);
|
||||
@@ -320,11 +285,11 @@ namespace Convention
|
||||
|
||||
public:
|
||||
Listening(const std::function<void(const ISignal&)>& action, TypeID type)
|
||||
: __init(action),__init(type){ }
|
||||
: __init(action), __init(type) {}
|
||||
Listening(const std::function<void(const ISignal&)>& action, Type type)
|
||||
: __init(action), type(type.hash_code()) {}
|
||||
|
||||
void StopListening()
|
||||
void StopListening() const
|
||||
{
|
||||
if (SingletonModel<Architecture>::Instance().SignalListener.count(type))
|
||||
SingletonModel<Architecture>::Instance().SignalListener[type].erase(action);
|
||||
@@ -349,7 +314,7 @@ namespace Convention
|
||||
template<typename Signal>
|
||||
Listening AddListener(std::enable_if_t<std::is_base_of_v<ISignal, Signal>, std::function<void(const Signal&)>> listener)
|
||||
{
|
||||
return AddListener<Signal>(typeof(Signal), listener);
|
||||
return AddListener<Signal>(typeid(Signal), listener);
|
||||
}
|
||||
|
||||
void SendMessage(Type slot, const ISignal& signal)
|
||||
@@ -366,7 +331,7 @@ namespace Convention
|
||||
template<typename Signal>
|
||||
void SendMessage(std::enable_if_t<std::is_base_of_v<ISignal, Signal>, const Signal&> signal)
|
||||
{
|
||||
return SendMessage(signal.GetType(), signal);
|
||||
return SendMessage(typeid(Signal), signal);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
@@ -8,43 +8,43 @@ namespace Convention
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
// Mathematical constants
|
||||
template<typename T>
|
||||
struct Constants
|
||||
{
|
||||
static constexpr T PI = static_cast<T>(3.14159265358979323846);
|
||||
static constexpr T E = static_cast<T>(2.71828182845904523536);
|
||||
static constexpr T SQRT2 = static_cast<T>(1.41421356237309504880);
|
||||
static constexpr T SQRT3 = static_cast<T>(1.73205080756887729353);
|
||||
static constexpr T LN2 = static_cast<T>(0.69314718055994530942);
|
||||
static constexpr T LN10 = static_cast<T>(2.30258509299404568402);
|
||||
};
|
||||
|
||||
// Basic math utilities
|
||||
template<typename T>
|
||||
constexpr T Abs(const T& value)
|
||||
inline T Abs(const T& value)
|
||||
{
|
||||
return value < T{} ? -value : value;
|
||||
return std::abs(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T Min(const T& a, const T& b)
|
||||
inline T Min(const T& a, const T& b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
return std::min(a, b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T Max(const T& a, const T& b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
template<typename T, typename... Args>
|
||||
inline T Min(const T& a, const Args&... args)
|
||||
{
|
||||
return std::min(a, Min<T>(args...));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T Clamp(const T& value, const T& min, const T& max)
|
||||
inline T Max(const T& a, const T& b)
|
||||
{
|
||||
return Min(Max(value, min), max);
|
||||
return std::max(a, b);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline T Max(const T& a, const Args&... args)
|
||||
{
|
||||
return std::max(a, Max<T>(args...));
|
||||
}
|
||||
|
||||
template<typename T,typename T2,typename T3>
|
||||
constexpr T Clamp(const T& value, const T2& min, const T3& max)
|
||||
{
|
||||
return Min<T>(Max<T>(value, min), max);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T Sign(const T& value)
|
||||
{
|
||||
@@ -117,13 +117,13 @@ namespace Convention
|
||||
template<typename T>
|
||||
constexpr T DegToRad(const T& degrees)
|
||||
{
|
||||
return degrees * Constants<T>::PI / static_cast<T>(180);
|
||||
return degrees * std::_Pi_val / static_cast<T>(180);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T RadToDeg(const T& radians)
|
||||
{
|
||||
return radians * static_cast<T>(180) / Constants<T>::PI;
|
||||
return radians * static_cast<T>(180) / std::_Pi_val;
|
||||
}
|
||||
|
||||
// Logarithmic functions
|
||||
@@ -291,4 +291,4 @@ namespace Convention
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Convention_Runtime_Math_hpp
|
||||
#endif // Convention_Runtime_Math_hpp
|
||||
|
@@ -3,377 +3,10 @@
|
||||
#define Convention_Runtime_Plugins_hpp
|
||||
|
||||
#include "Config.hpp"
|
||||
#include "Architecture.hpp"
|
||||
|
||||
namespace Convention
|
||||
{
|
||||
// Priority Queue implementation for plugin priorities
|
||||
template<typename T>
|
||||
class PriorityQueue
|
||||
{
|
||||
public:
|
||||
enum class Comparator
|
||||
{
|
||||
Less = -1,
|
||||
Equal = 0,
|
||||
Greater = 1
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<T> elements;
|
||||
std::function<int(const T&, const T&)> compare_func;
|
||||
Comparator comparator;
|
||||
|
||||
public:
|
||||
PriorityQueue(Comparator comp = Comparator::Less, size_t capacity = 1)
|
||||
: comparator(comp)
|
||||
{
|
||||
elements.reserve(std::max(capacity, size_t{1}));
|
||||
|
||||
compare_func = [comp](const T& a, const T& b) -> int {
|
||||
if constexpr (std::is_arithmetic_v<T>) {
|
||||
int result = (a > b) - (a < b);
|
||||
return result * static_cast<int>(comp);
|
||||
} else {
|
||||
if (a < b) return -1 * static_cast<int>(comp);
|
||||
if (b < a) return 1 * static_cast<int>(comp);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename Compare>
|
||||
PriorityQueue(Compare comp, size_t capacity = 1)
|
||||
: compare_func(comp)
|
||||
{
|
||||
elements.reserve(std::max(capacity, size_t{1}));
|
||||
}
|
||||
|
||||
// Basic properties
|
||||
size_t Size() const { return elements.size(); }
|
||||
size_t Count() const { return Size(); }
|
||||
size_t Capacity() const { return elements.capacity(); }
|
||||
bool IsEmpty() const { return elements.empty(); }
|
||||
|
||||
const T& Top() const
|
||||
{
|
||||
if (IsEmpty()) throw std::runtime_error("Queue is empty");
|
||||
return elements[0];
|
||||
}
|
||||
|
||||
// Core operations
|
||||
void Enqueue(const T& value)
|
||||
{
|
||||
elements.push_back(value);
|
||||
ShiftUp(elements.size() - 1);
|
||||
}
|
||||
|
||||
void Enqueue(T&& value)
|
||||
{
|
||||
elements.push_back(std::move(value));
|
||||
ShiftUp(elements.size() - 1);
|
||||
}
|
||||
|
||||
T Dequeue()
|
||||
{
|
||||
if (IsEmpty()) throw std::runtime_error("Queue is empty");
|
||||
|
||||
T result = std::move(elements[0]);
|
||||
elements[0] = std::move(elements.back());
|
||||
elements.pop_back();
|
||||
|
||||
if (!IsEmpty()) {
|
||||
ShiftDown(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TryDequeue(T& result)
|
||||
{
|
||||
if (IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
result = Dequeue();
|
||||
return true;
|
||||
}
|
||||
|
||||
const T& Peek() const
|
||||
{
|
||||
return Top();
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
bool Contains(const T& item) const
|
||||
{
|
||||
return std::find(elements.begin(), elements.end(), item) != elements.end();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
elements.clear();
|
||||
}
|
||||
|
||||
std::vector<T> ToArray() const
|
||||
{
|
||||
return elements;
|
||||
}
|
||||
|
||||
void TrimExcess()
|
||||
{
|
||||
if (elements.size() < elements.capacity() * 0.9) {
|
||||
elements.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
void EnsureCapacity(size_t minCapacity)
|
||||
{
|
||||
if (elements.capacity() < minCapacity) {
|
||||
elements.reserve(minCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void ShiftUp(size_t index)
|
||||
{
|
||||
while (index > 0) {
|
||||
size_t parent = (index - 1) / 2;
|
||||
if (compare_func(elements[index], elements[parent]) >= 0) break;
|
||||
|
||||
std::swap(elements[index], elements[parent]);
|
||||
index = parent;
|
||||
}
|
||||
}
|
||||
|
||||
void ShiftDown(size_t index)
|
||||
{
|
||||
size_t size = elements.size();
|
||||
while (true) {
|
||||
size_t left = 2 * index + 1;
|
||||
size_t right = 2 * index + 2;
|
||||
size_t smallest = index;
|
||||
|
||||
if (left < size && compare_func(elements[left], elements[smallest]) < 0) {
|
||||
smallest = left;
|
||||
}
|
||||
if (right < size && compare_func(elements[right], elements[smallest]) < 0) {
|
||||
smallest = right;
|
||||
}
|
||||
|
||||
if (smallest == index) break;
|
||||
|
||||
std::swap(elements[index], elements[smallest]);
|
||||
index = smallest;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Plugin base interface
|
||||
class IPlugin
|
||||
{
|
||||
public:
|
||||
virtual ~IPlugin() = default;
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual std::string GetVersion() const = 0;
|
||||
virtual bool Initialize() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual int GetPriority() const { return 0; }
|
||||
};
|
||||
|
||||
// Plugin information
|
||||
struct PluginInfo
|
||||
{
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::string description;
|
||||
std::vector<std::string> dependencies;
|
||||
int priority = 0;
|
||||
bool enabled = true;
|
||||
};
|
||||
|
||||
// Plugin manager interface
|
||||
class PluginManager
|
||||
{
|
||||
public:
|
||||
static PluginManager& GetInstance()
|
||||
{
|
||||
static PluginManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Plugin registration (interface only)
|
||||
template<typename T>
|
||||
bool RegisterPlugin()
|
||||
{
|
||||
static_assert(std::is_base_of_v<IPlugin, T>, "T must inherit from IPlugin");
|
||||
|
||||
// TODO: Implement plugin registration
|
||||
// This would typically involve:
|
||||
// 1. Creating instance of T
|
||||
// 2. Calling Initialize()
|
||||
// 3. Adding to plugin registry
|
||||
// 4. Managing dependencies
|
||||
|
||||
throw std::runtime_error("Plugin system implementation required");
|
||||
}
|
||||
|
||||
bool LoadPlugin(const std::string& pluginPath)
|
||||
{
|
||||
// TODO: Implement dynamic plugin loading
|
||||
// This would typically involve:
|
||||
// 1. Loading shared library (.dll/.so/.dylib)
|
||||
// 2. Finding plugin entry point
|
||||
// 3. Creating plugin instance
|
||||
// 4. Registering plugin
|
||||
|
||||
throw std::runtime_error("Dynamic plugin loading implementation required");
|
||||
}
|
||||
|
||||
bool UnloadPlugin(const std::string& pluginName)
|
||||
{
|
||||
// TODO: Implement plugin unloading
|
||||
throw std::runtime_error("Plugin unloading implementation required");
|
||||
}
|
||||
|
||||
std::vector<PluginInfo> GetLoadedPlugins() const
|
||||
{
|
||||
// TODO: Return list of loaded plugins
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* GetPlugin(const std::string& name) const
|
||||
{
|
||||
// TODO: Find plugin by name and cast to type T
|
||||
throw std::runtime_error("Plugin retrieval implementation required");
|
||||
}
|
||||
|
||||
bool IsPluginLoaded(const std::string& name) const
|
||||
{
|
||||
// TODO: Check if plugin is loaded
|
||||
return false;
|
||||
}
|
||||
|
||||
void EnablePlugin(const std::string& name)
|
||||
{
|
||||
// TODO: Enable plugin
|
||||
}
|
||||
|
||||
void DisablePlugin(const std::string& name)
|
||||
{
|
||||
// TODO: Disable plugin
|
||||
}
|
||||
|
||||
// Plugin discovery
|
||||
std::vector<std::string> DiscoverPlugins(const std::string& directory) const
|
||||
{
|
||||
// TODO: Scan directory for plugin files
|
||||
throw std::runtime_error("Plugin discovery implementation required");
|
||||
}
|
||||
|
||||
// Event system integration
|
||||
template<typename EventType>
|
||||
void BroadcastEvent(const EventType& event)
|
||||
{
|
||||
// TODO: Send event to all registered plugins
|
||||
// Integration with Architecture's event system
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<IPlugin>> loaded_plugins;
|
||||
std::map<std::string, PluginInfo> plugin_info;
|
||||
PriorityQueue<std::shared_ptr<IPlugin>> priority_queue;
|
||||
|
||||
PluginManager() = default;
|
||||
};
|
||||
|
||||
// Platform-specific plugin utilities
|
||||
namespace Platform
|
||||
{
|
||||
// Windows-specific functionality (interface only)
|
||||
class WindowsPlugin : public IPlugin
|
||||
{
|
||||
public:
|
||||
std::string GetName() const override { return "WindowsPlugin"; }
|
||||
std::string GetVersion() const override { return "1.0.0"; }
|
||||
|
||||
bool Initialize() override
|
||||
{
|
||||
// TODO: Initialize Windows-specific features
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() override
|
||||
{
|
||||
// TODO: Cleanup Windows-specific resources
|
||||
}
|
||||
|
||||
// Windows-specific methods (interface only)
|
||||
bool ShowMessageBox(const std::string& title, const std::string& message)
|
||||
{
|
||||
// TODO: Implement using Windows API
|
||||
throw std::runtime_error("Windows API implementation required");
|
||||
}
|
||||
|
||||
std::string GetSystemInfo()
|
||||
{
|
||||
// TODO: Get Windows system information
|
||||
throw std::runtime_error("Windows API implementation required");
|
||||
}
|
||||
};
|
||||
|
||||
// Linux-specific functionality (interface only)
|
||||
class LinuxPlugin : public IPlugin
|
||||
{
|
||||
public:
|
||||
std::string GetName() const override { return "LinuxPlugin"; }
|
||||
std::string GetVersion() const override { return "1.0.0"; }
|
||||
|
||||
bool Initialize() override
|
||||
{
|
||||
// TODO: Initialize Linux-specific features
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() override
|
||||
{
|
||||
// TODO: Cleanup Linux-specific resources
|
||||
}
|
||||
|
||||
// Linux-specific methods (interface only)
|
||||
std::string GetSystemInfo()
|
||||
{
|
||||
// TODO: Get Linux system information
|
||||
throw std::runtime_error("Linux API implementation required");
|
||||
}
|
||||
};
|
||||
|
||||
// Factory for platform-specific plugins
|
||||
std::shared_ptr<IPlugin> CreatePlatformPlugin()
|
||||
{
|
||||
if (PlatformIndicator::IsPlatformWindows) {
|
||||
return std::make_shared<WindowsPlugin>();
|
||||
} else if (PlatformIndicator::IsPlatformLinux) {
|
||||
return std::make_shared<LinuxPlugin>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin helper macros
|
||||
#define DECLARE_PLUGIN(ClassName) \
|
||||
extern "C" Convention::IPlugin* CreatePlugin() { \
|
||||
return new ClassName(); \
|
||||
} \
|
||||
extern "C" void DestroyPlugin(Convention::IPlugin* plugin) { \
|
||||
delete plugin; \
|
||||
}
|
||||
|
||||
#define REGISTER_PLUGIN(ClassName) \
|
||||
bool Register##ClassName() { \
|
||||
return Convention::PluginManager::GetInstance().RegisterPlugin<ClassName>(); \
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Convention_Runtime_Plugins_hpp
|
||||
#endif // Convention_Runtime_Plugins_hpp
|
||||
|
Reference in New Issue
Block a user