diff --git a/include/cppast/cpp_class_template.hpp b/include/cppast/cpp_class_template.hpp new file mode 100644 index 0000000..30677a1 --- /dev/null +++ b/include/cppast/cpp_class_template.hpp @@ -0,0 +1,73 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#ifndef CPPAST_CPP_CLASS_TEMPLATE_HPP_INCLUDED +#define CPPAST_CPP_CLASS_TEMPLATE_HPP_INCLUDED + +#include +#include + +namespace cppast +{ + /// A [cppast::cpp_entity]() modelling a class template. + class cpp_class_template final : public cpp_template + { + public: + /// Builder for [cppast::cpp_class_template](). + class builder : public basic_builder + { + public: + using basic_builder::basic_builder; + }; + + /// A reference to the class that is being templated. + const cpp_class& class_() const noexcept + { + return static_cast(*begin()); + } + + private: + cpp_class_template(std::unique_ptr func) + : cpp_template(std::unique_ptr(func.release())) + { + } + + cpp_entity_kind do_get_entity_kind() const noexcept override; + + friend basic_builder; + }; + + /// A [cppast::cpp_entity]() modelling a class template specialization. + class cpp_class_template_specialization final : public cpp_template_specialization + { + public: + /// Builder for [cppast::cpp_class_template_specialization](). + class builder : public specialization_builder + { + public: + using specialization_builder::specialization_builder; + + private: + using specialization_builder::add_parameter; + }; + + /// A reference to the class that is being specialized. + const cpp_class& class_() const noexcept + { + return static_cast(*begin()); + } + + private: + cpp_class_template_specialization(std::unique_ptr func, cpp_template_ref primary) + : cpp_template_specialization(std::unique_ptr(func.release()), primary) + { + } + + cpp_entity_kind do_get_entity_kind() const noexcept override; + + friend specialization_builder; + }; +} // namespace cppast + +#endif // CPPAST_CPP_CLASS_TEMPLATE_HPP_INCLUDED diff --git a/include/cppast/cpp_entity_kind.hpp b/include/cppast/cpp_entity_kind.hpp index 847d1ec..1a66bb4 100644 --- a/include/cppast/cpp_entity_kind.hpp +++ b/include/cppast/cpp_entity_kind.hpp @@ -48,6 +48,8 @@ namespace cppast alias_template_t, function_template_t, function_template_specialization_t, + class_template_t, + class_template_specialization_t, count, }; diff --git a/src/cpp_class_template.cpp b/src/cpp_class_template.cpp new file mode 100644 index 0000000..d645577 --- /dev/null +++ b/src/cpp_class_template.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Jonathan Müller +// This file is subject to the license terms in the LICENSE file +// found in the top-level directory of this distribution. + +#include + +#include + +using namespace cppast; + +cpp_entity_kind cpp_class_template::do_get_entity_kind() const noexcept +{ + return cpp_entity_kind::class_template_t; +} + +cpp_entity_kind cpp_class_template_specialization::do_get_entity_kind() const noexcept +{ + return cpp_entity_kind::class_template_specialization_t; +} diff --git a/src/cpp_entity_kind.cpp b/src/cpp_entity_kind.cpp index 40c4ed8..a0d033d 100644 --- a/src/cpp_entity_kind.cpp +++ b/src/cpp_entity_kind.cpp @@ -73,6 +73,10 @@ const char* cppast::to_string(cpp_entity_kind kind) noexcept return "function template"; case cpp_entity_kind::function_template_specialization_t: return "function template specialization"; + case cpp_entity_kind::class_template_t: + return "class template"; + case cpp_entity_kind::class_template_specialization_t: + return "class tempalte specialization"; case cpp_entity_kind::count: break; @@ -114,6 +118,8 @@ bool cppast::is_type(cpp_entity_kind kind) noexcept case cpp_entity_kind::alias_template_t: case cpp_entity_kind::function_template_t: case cpp_entity_kind::function_template_specialization_t: + case cpp_entity_kind::class_template_t: + case cpp_entity_kind::class_template_specialization_t: case cpp_entity_kind::count: break; } @@ -128,6 +134,8 @@ bool cppast::is_template(cpp_entity_kind kind) noexcept case cpp_entity_kind::alias_template_t: case cpp_entity_kind::function_template_t: case cpp_entity_kind::function_template_specialization_t: + case cpp_entity_kind::class_template_t: + case cpp_entity_kind::class_template_specialization_t: return true; case cpp_entity_kind::file_t: diff --git a/src/visitor.cpp b/src/visitor.cpp index 10c9347..7ec3193 100644 --- a/src/visitor.cpp +++ b/src/visitor.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,10 @@ bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* fun return handle_container(e, cb, functor); case cpp_entity_kind::function_template_specialization_t: return handle_container(e, cb, functor); + case cpp_entity_kind::class_template_t: + return handle_container(e, cb, functor); + case cpp_entity_kind::class_template_specialization_t: + return handle_container(e, cb, functor); case cpp_entity_kind::namespace_alias_t: case cpp_entity_kind::using_directive_t: