Added cli options for cppidx generator
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* src/class_diagram/generators/cppidx/class_diagram_generator.cc
|
||||
*
|
||||
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "class_diagram_generator.h"
|
||||
|
||||
#include "util/error.h"
|
||||
|
||||
namespace clanguml::class_diagram::generators::cppidx {
|
||||
|
||||
generator::generator(diagram_config &config, diagram_model &model)
|
||||
: common_generator<diagram_config, diagram_model>{config, model}
|
||||
{
|
||||
}
|
||||
|
||||
void generator::generate(std::ostream &ostr) const
|
||||
{
|
||||
generate_top_level_elements(ostr);
|
||||
|
||||
ostr << json_;
|
||||
}
|
||||
|
||||
void generator::generate_top_level_elements(std::ostream &ostr) const
|
||||
{
|
||||
for (const auto &p : m_model) {
|
||||
if (auto *cls = dynamic_cast<class_ *>(p.get()); cls) {
|
||||
if (m_model.should_include(*cls)) {
|
||||
generate(*cls, ostr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void generator::generate(const class_ &c, std::ostream & /*ostr*/) const
|
||||
{
|
||||
|
||||
nlohmann::json object;
|
||||
object["id"] = std::to_string(c.id());
|
||||
object["name"] = c.name();
|
||||
object["namespace"] = c.get_namespace().to_string();
|
||||
object["type"] = c.type_name();
|
||||
object["display_name"] = c.full_name(false);
|
||||
json_["elements"].push_back(std::move(object));
|
||||
}
|
||||
|
||||
} // namespace clanguml::class_diagram::generators::plantuml
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* src/class_diagram/generators/cppidx/class_diagram_generator.h
|
||||
*
|
||||
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "class_diagram/model/class.h"
|
||||
#include "class_diagram/model/concept.h"
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "class_diagram/model/enum.h"
|
||||
#include "class_diagram/visitor/translation_unit_visitor.h"
|
||||
#include "common/generators/cppidx/generator.h"
|
||||
#include "common/generators/nested_element_stack.h"
|
||||
#include "common/model/relationship.h"
|
||||
#include "config/config.h"
|
||||
#include "util/util.h"
|
||||
|
||||
#include <glob/glob.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace clanguml {
|
||||
namespace class_diagram {
|
||||
namespace generators {
|
||||
namespace cppidx {
|
||||
|
||||
using diagram_config = clanguml::config::class_diagram;
|
||||
using diagram_model = clanguml::class_diagram::model::diagram;
|
||||
template <typename C, typename D>
|
||||
using common_generator = clanguml::common::generators::cppidx::generator<C, D>;
|
||||
|
||||
using clanguml::class_diagram::model::class_;
|
||||
using clanguml::class_diagram::model::class_element;
|
||||
using clanguml::class_diagram::model::concept_;
|
||||
using clanguml::class_diagram::model::enum_;
|
||||
using clanguml::common::model::access_t;
|
||||
using clanguml::common::model::package;
|
||||
using clanguml::common::model::relationship_t;
|
||||
|
||||
using namespace clanguml::util;
|
||||
|
||||
class generator : public common_generator<diagram_config, diagram_model> {
|
||||
public:
|
||||
generator(diagram_config &config, diagram_model &model);
|
||||
|
||||
void generate(const class_ &c, std::ostream &ostr) const;
|
||||
|
||||
void generate_top_level_elements(std::ostream &ostr) const;
|
||||
|
||||
void generate(std::ostream &ostr) const override;
|
||||
|
||||
private:
|
||||
std::string render_name(std::string name) const;
|
||||
|
||||
mutable nlohmann::json json_;
|
||||
};
|
||||
|
||||
} // namespace cppidx
|
||||
} // namespace generators
|
||||
} // namespace class_diagram
|
||||
} // namespace clanguml
|
||||
Reference in New Issue
Block a user