feat(mcp): Finalize C/C++ AST tools with robust testing and bug fixes

This commit is contained in:
2026-05-05 20:08:51 -04:00
parent 584e8e526e
commit 992e206769
10 changed files with 468 additions and 230 deletions
@@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <memory>
#include <vector>
namespace gencpp {
namespace core {
/**
* @brief Base class for all components in the system.
*/
template <typename T>
class BaseComponent {
public:
virtual ~BaseComponent() = default;
virtual void Initialize() = 0;
virtual void Shutdown() = 0;
virtual const std::string& GetName() const = 0;
struct Config {
std::string name;
int priority;
bool enabled;
class Metadata {
public:
std::string author;
std::string version;
};
Metadata metadata;
};
protected:
BaseComponent(const Config& config) : m_config(config) {}
Config m_config;
};
} // namespace core
} // namespace gencpp
@@ -0,0 +1,54 @@
#pragma once
#include <tuple>
#include <utility>
namespace gencpp {
namespace util {
/**
* @brief A complex template class demonstrating variadic templates.
*/
template <typename... Args>
class MultiBuffer {
public:
void SetData(Args... args) {
m_data = std::make_tuple(args...);
}
template <size_t I>
auto Get() const -> const typename std::tuple_element<I, std::tuple<Args...>>::type& {
return std::get<I>(m_data);
}
private:
std::tuple<Args...> m_data;
};
/**
* @brief Template specialization example.
*/
template <typename T>
struct TypeTraits {
static constexpr bool IsPointer = false;
};
template <typename T>
struct TypeTraits<T*> {
static constexpr bool IsPointer = true;
};
/**
* @brief Nested template class.
*/
template <typename Outer>
struct Container {
template <typename Inner>
struct Wrapper {
Inner value;
Outer context;
};
};
} // namespace util
} // namespace gencpp
@@ -0,0 +1,26 @@
#include "component_registry.h"
#include <iostream>
namespace gencpp {
namespace registry {
ComponentRegistry& ComponentRegistry::Instance() {
static ComponentRegistry instance;
return instance;
}
void ComponentRegistry::Register(const std::string& type, ComponentCreator creator) {
std::cout << "Registering component type: " << type << std::endl;
m_creators[type] = creator;
}
std::unique_ptr<core::BaseComponent<void*>> ComponentRegistry::Create(const std::string& type) {
auto it = m_creators.find(type);
if (it != m_creators.end()) {
return it->second();
}
return nullptr;
}
} // namespace registry
} // namespace gencpp
@@ -0,0 +1,43 @@
#pragma once
#include "base_component.h"
#include <map>
#include <string>
#include <functional>
namespace gencpp {
namespace registry {
class ComponentRegistry {
public:
using ComponentCreator = std::function<std::unique_ptr<core::BaseComponent<void*>>()>;
static ComponentRegistry& Instance();
void Register(const std::string& type, ComponentCreator creator);
std::unique_ptr<core::BaseComponent<void*>> Create(const std::string& type);
class Iterator {
public:
using MapIterator = std::map<std::string, ComponentCreator>::iterator;
Iterator(MapIterator it) : m_it(it) {}
bool operator!=(const Iterator& other) const { return m_it != other.m_it; }
void operator++() { ++m_it; }
const std::string& GetType() const { return m_it->first; }
private:
MapIterator m_it;
};
Iterator Begin() { return Iterator(m_creators.begin()); }
Iterator End() { return Iterator(m_creators.end()); }
private:
ComponentRegistry() = default;
std::map<std::string, ComponentCreator> m_creators;
};
} // namespace registry
} // namespace gencpp
@@ -0,0 +1,20 @@
import os
def verify_files():
files = [
"base_component.h",
"component_registry.h",
"component_registry.cpp",
"complex_template.h"
]
base_path = "tests/assets/gencpp_samples"
for f in files:
p = os.path.join(base_path, f)
if os.path.exists(p):
print(f"Verified: {f}")
else:
print(f"Missing: {f}")
exit(1)
if __name__ == "__main__":
verify_files()