Sen API
Sen Libraries
Loading...
Searching...
No Matches
gen/src/common/util.h
Go to the documentation of this file.
1// === util.h ==========================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_LIBS_GEN_SRC_COMMON_UTIL_H
9#define SEN_LIBS_GEN_SRC_COMMON_UTIL_H
10
11// sen
14
15// inja
16#include <inja/environment.hpp>
17
18// std
19#include <cstddef>
20#include <iomanip>
21#include <sstream>
22#include <string>
23#include <string_view>
24#include <vector>
25
26namespace sen::gen::detail
27{
28
29namespace impl
30{
31constexpr std::size_t maxCommentLineLength = 80U;
32} // namespace impl
33
35void configureEnv(inja::Environment& env);
36
38[[nodiscard]] std::vector<std::string> tokenize(const std::string& str, const char delim);
39
41[[nodiscard]] std::string prepend(const std::string& prefix, const std::string str);
42
44[[nodiscard]] std::string append(const std::string& lhs, const std::string rhs);
45
47[[nodiscard]] std::string capitalize(const std::string& str);
48
50[[nodiscard]] std::string capitalize(std::string_view str);
51
53[[nodiscard]] std::string computeCppNamespace(const std::vector<std::string>& package);
54
56[[nodiscard]] std::string computeCppNamespace(const sen::lang::TypeSet& set);
57
59[[nodiscard]] std::string computeCppNamespace(const sen::CustomType& type);
60
65[[nodiscard]] std::vector<const sen::lang::TypeSet*> collectAllTypeSets(const sen::lang::TypeSetContext& typeSets);
66
67template <typename T>
68[[nodiscard]] std::string intToHex(T i)
69{
70 std::stringstream stream;
71 stream << "0x" << std::setfill('0') << std::setw(sizeof(T) + sizeof(T)) << std::hex << i;
72 return stream.str();
73}
74
75template <typename T>
76[[nodiscard]] std::string intToHex2(T i)
77{
78 std::stringstream stream;
79 stream << "0x" << std::setfill('0') << std::setw(sizeof(T)) << std::hex << i;
80 return stream.str();
81}
82
83} // namespace sen::gen::detail
84
85#endif // SEN_LIBS_GEN_SRC_COMMON_UTIL_H
Represents a user-defined type.
Definition custom_type.h:23
The set of types used during resolution.
Definition stl_resolver.h:51
A set of types coming from a STL file.
Definition stl_resolver.h:33
Definition gen/src/common/util.h:30
constexpr std::size_t maxCommentLineLength
Definition gen/src/common/util.h:31
Definition type_storage.h:28
std::string intToHex2(T i)
Definition gen/src/common/util.h:76
std::string append(const std::string &lhs, const std::string rhs)
Appends a suffix to the end of a given string.
std::string intToHex(T i)
Definition gen/src/common/util.h:68
std::string capitalize(const std::string &str)
Transform a string to uppercase.
std::string prepend(const std::string &prefix, const std::string str)
Appends a prefix to the beginning of a given string.
std::vector< const sen::lang::TypeSet * > collectAllTypeSets(const sen::lang::TypeSetContext &typeSets)
Walks the given context's type sets and their imports depth-first, returning unique sets in insertion...
void configureEnv(inja::Environment &env)
Registers inja helper callbacks used by generator templates.
std::string computeCppNamespace(const std::vector< std::string > &package)
Computes C++ namespace from a string package.
std::vector< std::string > tokenize(const std::string &str, const char delim)
Splits a string into substrings by a delimiter, skipping empty results.