Skip to content

Commit 7e5297a

Browse files
fixup
1 parent cb719c2 commit 7e5297a

File tree

13 files changed

+244
-45
lines changed

13 files changed

+244
-45
lines changed

tesseract_collision/core/src/contact_managers_plugin_factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
3333
#include <tesseract_collision/core/continuous_contact_manager.h>
3434
#include <tesseract_common/resource_locator.h>
3535
#include <tesseract_common/yaml_utils.h>
36-
#include <tesseract_common/yaml_extenstions.h>
36+
#include <tesseract_common/yaml_extensions.h>
3737
#include <tesseract_common/property_tree.h>
3838
#include <tesseract_collision/core/contact_managers_plugin_factory.h>
3939
#include <boost_plugin_loader/plugin_loader.hpp>

tesseract_common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ add_library(
101101
src/stopwatch.cpp
102102
src/types.cpp
103103
src/timer.cpp
104+
src/yaml_extensions.cpp
104105
src/yaml_utils.cpp)
105106
target_link_libraries(
106107
${PROJECT_NAME}

tesseract_common/include/tesseract_common/property_tree.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ namespace tesseract_common
1414
namespace property_type
1515
{
1616
/**
17-
* @brief A utility for constructing the std::vector<type>
17+
* @brief A utility for constructing the vector<type>
1818
* @param type The type assoicated with the list
19-
* @return The string representation of the std::vector<type>, aka. type[]
19+
* @param length The length if fixed size
20+
* @return The string representation of the vector<type>, aka. type[] and type[length] for fixed size
2021
*/
21-
std::string createList(std::string_view type);
22+
std::string createList(std::string_view type, std::size_t length = 0);
2223

2324
/**
24-
* @brief A utility for constructing the std::map<std::string, type>
25+
* @brief A utility for constructing the map<std::string, type>
2526
* @param type The value type assoicated with the map
26-
* @return The string representation of the std::map<std::string, type>, aka. type{}
27+
* @return The string representation of the map<std::string, type>, aka. {string,string}
2728
*/
2829
std::string createMap(std::string_view type);
2930

31+
/**
32+
* @brief A utility for constructing the map<key, type>
33+
* @param type The value type assoicated with the map
34+
* @return The string representation of the map<key, type>, aka. {string, string} or {string[2], string}
35+
*/
36+
std::string createMap(std::string_view key, std::string_view type);
37+
3038
// Integral Types
3139
constexpr std::string_view BOOL{ "bool" };
3240
constexpr std::string_view CHAR{ "char" };
@@ -272,16 +280,16 @@ class PropertyTree
272280
/**
273281
* @brief Check if type is a sequence
274282
* @param type The type to check
275-
* @return If it is a sequence, the underlying type is returned
283+
* @return If it is a sequence, the underlying type is returned and size
276284
*/
277-
std::optional<std::string> isSequenceType(std::string_view type);
285+
std::optional<std::pair<std::string, std::size_t>> isSequenceType(std::string_view type);
278286

279287
/**
280288
* @brief Check if type is a map
281289
* @param type The type to check
282-
* @return If it is a map, the underlying type is returned
290+
* @return If it is a map, the underlying pair<key,type> is returned
283291
*/
284-
std::optional<std::string> isMapType(std::string_view type);
292+
std::optional<std::pair<std::string, std::string>> isMapType(std::string_view type);
285293

286294
/**
287295
* @brief Validator: ensure 'required' attribute is present and non-null.
@@ -307,9 +315,10 @@ void validateMap(const PropertyTree& node);
307315
/**
308316
* @brief Validtor: ensure node value is of type YAML::NodeType::Sequence
309317
* @param node Node to validate.
318+
* @param length The length if fixed size. If zero, it is considered dynamic size sequence
310319
* @throws runtime_error if not correct type.
311320
*/
312-
void validateSequence(const PropertyTree& node);
321+
void validateSequence(const PropertyTree& node, std::size_t length = 0);
313322

314323
/**
315324
* @brief Validator: ensure property is a container of child properties

tesseract_common/include/tesseract_common/schema_registration.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ struct SchemaRegistrar
1717

1818
} // namespace tesseract_common
1919

20+
// first level: does the actual pasting
21+
#define _SCHEMA_REG_PASTE(a, b) a##b
22+
23+
// second level: expands its arguments before passing to the first
24+
#define _SCHEMA_REG_MAKE_NAME(a, b) _SCHEMA_REG_PASTE(a, b)
25+
2026
/// Macro to register either a file‐based schema or a function‐built schema
2127
#define TESSERACT_REGISTER_SCHEMA(KEY, SCHEMA_SOURCE) \
2228
namespace \
2329
{ \
2430
/* now a const POD, linter is happy */ \
25-
static const int _reg_##KEY = []() -> int { \
31+
static const int _SCHEMA_REG_MAKE_NAME(_schema_reg_, __COUNTER__) = []() -> int { \
2632
using namespace tesseract_common; \
2733
/* calls the appropriate SchemaRegistrar constructor */ \
2834
SchemaRegistrar(#KEY, SCHEMA_SOURCE); \

tesseract_common/include/tesseract_common/yaml_extenstions.h renamed to tesseract_common/include/tesseract_common/yaml_extensions.h

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file yaml_extenstions.h
2+
* @file yaml_extensions.h
33
* @brief YAML Type conversions
44
*
55
* @author Levi Armstrong
@@ -982,6 +982,40 @@ struct convert<tesseract_common::PairsCollisionMarginData>
982982
}
983983
return true;
984984
}
985+
986+
static tesseract_common::PropertyTree schema()
987+
{
988+
using namespace tesseract_common;
989+
using namespace property_attribute;
990+
using namespace property_type;
991+
992+
// top‐level must be a map container
993+
PropertyTree sch;
994+
sch.setAttribute(TYPE, "tesseract_common::PairsCollisionMarginData");
995+
sch.addValidator([](const PropertyTree& node) {
996+
const YAML::Node& yn = node.getValue();
997+
if (!yn.IsMap())
998+
std::throw_with_nested(std::runtime_error("PairsCollisionMarginData, must be a map"));
999+
1000+
for (auto it = yn.begin(); it != yn.end(); ++it)
1001+
{
1002+
Node key_node = it->first;
1003+
if (!key_node.IsSequence() || key_node.size() != 2)
1004+
std::throw_with_nested(std::runtime_error("PairsCollisionMarginData, key must be a sequenc of size 2"));
1005+
1006+
try
1007+
{
1008+
it->second.as<double>();
1009+
}
1010+
catch (const std::exception& e)
1011+
{
1012+
std::throw_with_nested(e);
1013+
}
1014+
}
1015+
});
1016+
1017+
return sch;
1018+
}
9851019
};
9861020

9871021
//================================== CollisionMarginPairData =================================
@@ -1000,6 +1034,19 @@ struct convert<tesseract_common::CollisionMarginPairData>
10001034
rhs = tesseract_common::CollisionMarginPairData(data);
10011035
return true;
10021036
}
1037+
1038+
static tesseract_common::PropertyTree schema()
1039+
{
1040+
using namespace tesseract_common;
1041+
using namespace property_attribute;
1042+
using namespace property_type;
1043+
1044+
// top‐level must be a map container
1045+
PropertyTree sch;
1046+
sch.setAttribute(TYPE, "tesseract_common::PairsCollisionMarginData");
1047+
1048+
return sch;
1049+
}
10031050
};
10041051

10051052
//============================ AllowedCollisionEntries ============================
@@ -1044,6 +1091,40 @@ struct convert<tesseract_common::AllowedCollisionEntries>
10441091
}
10451092
return true;
10461093
}
1094+
1095+
static tesseract_common::PropertyTree schema()
1096+
{
1097+
using namespace tesseract_common;
1098+
using namespace property_attribute;
1099+
using namespace property_type;
1100+
1101+
// top‐level must be a map container
1102+
PropertyTree sch;
1103+
sch.setAttribute(TYPE, "tesseract_common::AllowedCollisionEntries");
1104+
sch.addValidator([](const PropertyTree& node) {
1105+
const YAML::Node& yn = node.getValue();
1106+
if (!yn.IsMap())
1107+
std::throw_with_nested(std::runtime_error("AllowedCollisionEntries, must be a map"));
1108+
1109+
for (auto it = yn.begin(); it != yn.end(); ++it)
1110+
{
1111+
Node key_node = it->first;
1112+
if (!key_node.IsSequence() || key_node.size() != 2)
1113+
std::throw_with_nested(std::runtime_error("AllowedCollisionEntries, key must be a sequenc of size 2"));
1114+
1115+
try
1116+
{
1117+
it->second.as<std::string>();
1118+
}
1119+
catch (const std::exception& e)
1120+
{
1121+
std::throw_with_nested(e);
1122+
}
1123+
}
1124+
});
1125+
1126+
return sch;
1127+
}
10471128
};
10481129

10491130
//================================== AllowedCollisionMatrix =================================
@@ -1062,6 +1143,19 @@ struct convert<tesseract_common::AllowedCollisionMatrix>
10621143
rhs = tesseract_common::AllowedCollisionMatrix(data);
10631144
return true;
10641145
}
1146+
1147+
static tesseract_common::PropertyTree schema()
1148+
{
1149+
using namespace tesseract_common;
1150+
using namespace property_attribute;
1151+
using namespace property_type;
1152+
1153+
// top‐level must be a map container
1154+
PropertyTree sch;
1155+
sch.setAttribute(TYPE, "tesseract_common::AllowedCollisionEntries");
1156+
1157+
return sch;
1158+
}
10651159
};
10661160

10671161
//============================== std::unordered_map =============================

tesseract_common/src/plugin_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
4040
#include <tesseract_common/utils.h>
4141
#include <tesseract_common/plugin_info.h>
4242
#include <tesseract_common/yaml_utils.h>
43-
#include <tesseract_common/yaml_extenstions.h>
43+
#include <tesseract_common/yaml_extensions.h>
4444
#include <tesseract_common/property_tree.h>
4545

4646
namespace tesseract_common

0 commit comments

Comments
 (0)