DetectorGraph  2.0
nodenameutils.hpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DETECTORGRAPH_PLATFORM_STANDALONE_NODENAMEUTILS_HPP_
16 #define DETECTORGRAPH_PLATFORM_STANDALONE_NODENAMEUTILS_HPP_
17 
18 #include <string>
19 
20 namespace DetectorGraph
21 {
22 
23 namespace NodeNameUtils
24 {
25 
26 /**
27  * @brief Provides utilities for manipulating DetectorGraph node names.
28  *
29  * DetectorGraph Vertices (Detectors & Topics) and TopicStates have a GetName()
30  * API call that returns a compiler-specific string identifying that type.
31  *
32  * The utilities in this file were created to decode those names for either
33  * visualization or code-generation purposes.
34  *
35  * "You will never find a more wretched hive of scum and villainy. We must be
36  * cautious." - this code should not be used for anything serious.
37  */
38 
39 /**
40  * @brief Returns the Demangled name as a single-line string.
41  *
42  * This method uses cxxabi.h's __cxa_demangle to return the original names for
43  * objects. This works in the same way as c++filt.
44  */
45 std::string GetDemangledName(const std::string& aMangledString);
46 
47 /**
48  * @brief Returns a readable name with redundant prefixes/suffixes removed.
49  *
50  * For visualization purposes it may be useful to strip out common prefixes/
51  * suffixes on types (e.g. Detectors::Topics<>, TopicState).
52  */
53 std::string GetMinimalName(const std::string& aMangledString);
54 
55 
56 /**
57  * @brief Adds a \\n to the input name before common suffixes.
58  */
59 std::string WrapOnCommonEndings(const std::string& aNodeName);
60 
61 /**
62  * @brief Removes all elimStrings from aInStr and returns new string.
63  */
64 std::string RemoveSubstrings(const std::string& aInStr, const char* elimStrings[]);
65 
66 /**
67  * @brief Adds a \\n to aInStr before each sub-string in wrapStrings.
68  *
69  * Note that this will not add leading \\n even if the name starts with a string
70  * in wrapStrings.
71  */
72 std::string WrapOnSubStrings(const std::string& aInStr, const char* wrapStrings[]);
73 
74 }
75 
76 }
77 
78 #endif // DETECTORGRAPH_PLATFORM_STANDALONE_NODENAMEUTILS_HPP_
std::string GetDemangledName(const std::string &aMangledString)
Provides utilities for manipulating DetectorGraph node names.
std::string WrapOnCommonEndings(const std::string &aNodeName)
Adds a \n to the input name before common suffixes.
std::string WrapOnSubStrings(const std::string &aInStr, const char *wrapStrings[])
Adds a \n to aInStr before each sub-string in wrapStrings.
std::string RemoveSubstrings(const std::string &aInStr, const char *elimStrings[])
Removes all elimStrings from aInStr and returns new string.
std::string GetMinimalName(const std::string &aMangledString)
Returns a readable name with redundant prefixes/suffixes removed.