| 1 |
#ifndef ELEMENT_NAMING_UTILS_H |
| 2 |
#define ELEMENT_NAMING_UTILS_H |
| 3 |
|
| 4 |
#include <string> |
| 5 |
#include <utility> |
| 6 |
#include "FCGlobal.h" |
| 7 |
|
| 8 |
namespace App |
| 9 |
{ |
| 10 |
|
| 11 |
/** Return type for lookups of new and old style sub-element names |
| 12 |
* |
| 13 |
*/ |
| 14 |
struct ElementNamePair |
| 15 |
{ |
| 16 |
std::string newName; |
| 17 |
std::string oldName; |
| 18 |
|
| 19 |
ElementNamePair() = default; |
| 20 |
|
| 21 |
ElementNamePair(std::string newNameStr, std::string oldNameStr) |
| 22 |
: newName(std::move(newNameStr)) |
| 23 |
, oldName(std::move(oldNameStr)) |
| 24 |
{} |
| 25 |
|
| 26 |
bool operator==(const ElementNamePair& other) const |
| 27 |
{ |
| 28 |
return this->newName == other.newName && this->oldName == other.oldName; |
| 29 |
}; |
| 30 |
|
| 31 |
void swap(ElementNamePair& other) noexcept |
| 32 |
{ |
| 33 |
std::swap(*this, other); |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
} // namespace App |
| 38 |
|
| 39 |
// clang-format off |
| 40 |
namespace Data |
| 41 |
{ |
| 42 |
|
| 43 |
/// Special prefix to mark the beginning of a mapped sub-element name |
| 44 |
constexpr const char* ELEMENT_MAP_PREFIX = ";"; |
| 45 |
constexpr size_t ELEMENT_MAP_PREFIX_SIZE = 1; |
| 46 |
|
| 47 |
/// Special prefix to mark a missing element |
| 48 |
constexpr const char* MISSING_PREFIX = "?"; |
| 49 |
|
| 50 |
// IMPORTANT: For all the constants below, the semicolon ";" |
| 51 |
// at the start is ELEMENT_MAP_PREFIX |
| 52 |
|
| 53 |
constexpr const char* MAPPED_CHILD_ELEMENTS_PREFIX = ";:R"; |
| 54 |
|
| 55 |
/// Special postfix to mark the following tag |
| 56 |
constexpr const char* POSTFIX_TAG = ";:H"; |
| 57 |
constexpr size_t POSTFIX_TAG_SIZE = 3; |
| 58 |
|
| 59 |
constexpr const char* POSTFIX_DECIMAL_TAG = ";:T"; |
| 60 |
constexpr const char* POSTFIX_EXTERNAL_TAG = ";:X"; |
| 61 |
constexpr const char* POSTFIX_CHILD = ";:C"; |
| 62 |
|
| 63 |
/// Special postfix to mark the index of an array element |
| 64 |
constexpr const char* POSTFIX_INDEX = ";:I"; |
| 65 |
constexpr const char* POSTFIX_UPPER = ";:U"; |
| 66 |
constexpr const char* POSTFIX_LOWER = ";:L"; |
| 67 |
constexpr const char* POSTFIX_MOD = ";:M"; |
| 68 |
constexpr const char* POSTFIX_GEN = ";:G"; |
| 69 |
constexpr const char* POSTFIX_MODGEN = ";:MG"; |
| 70 |
constexpr const char* POSTFIX_DUPLICATE = ";D"; |
| 71 |
|
| 72 |
constexpr const char* ELEMENT_MAP_INDEX = "_"; |
| 73 |
|
| 74 |
/// Check if a subname contains missing element |
| 75 |
AppExport bool hasMissingElement(const char *subname); |
| 76 |
|
| 77 |
/** Check if the name starts with elementMapPrefix() |
| 78 |
* |
| 79 |
* @param name: input name |
| 80 |
* @return Returns the name stripped with elementMapPrefix(), or 0 if not |
| 81 |
* start with the prefix |
| 82 |
*/ |
| 83 |
AppExport const char *isMappedElement(const char *name); |
| 84 |
|
| 85 |
/// Strip out the trailing element name if there is mapped element name precedes it. |
| 86 |
AppExport std::string newElementName(const char *name); |
| 87 |
|
| 88 |
/// Strip out the mapped element name if there is one. |
| 89 |
AppExport std::string oldElementName(const char *name); |
| 90 |
|
| 91 |
/// Strip out the old and new element name if there is one. |
| 92 |
AppExport std::string noElementName(const char *name); |
| 93 |
|
| 94 |
/// Find the start of an element name in a subname |
| 95 |
AppExport const char *findElementName(const char *subname); |
| 96 |
|
| 97 |
AppExport const char *hasMappedElementName(const char *subname); |
| 98 |
|
| 99 |
AppExport const std::string indexSuffix(int index, const char *label=ELEMENT_MAP_INDEX); |
| 100 |
|
| 101 |
} // namespace Data |
| 102 |
// clang-format on |
| 103 |
|
| 104 |
#endif // ELEMENT_NAMING_UTILS_H |