Skip to content

Commit 8bb6ca7

Browse files
committed
split domain getter
1 parent 76351d0 commit 8bb6ca7

7 files changed

Lines changed: 137 additions & 48 deletions

File tree

cmake/f3dOptions.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ function (f3d_generate_options)
7676
list(JOIN _options_is_optional ";\n else " _options_is_optional)
7777
list(JOIN _options_reset ";\n else " _options_reset)
7878
list(JOIN _options_has_domain ";\n else " _options_has_domain)
79-
list(JOIN _options_get_domain ";\n else " _options_get_domain)
79+
list(JOIN _options_get_enum_domain ";\n else " _options_get_enum_domain)
80+
list(JOIN _options_get_range_domain ";\n else " _options_get_range_domain)
8081
list(JOIN _options_increase ";\n else " _options_increase)
8182
list(JOIN _options_cycle ";\n else " _options_cycle)
8283

@@ -261,7 +262,8 @@ function(_parse_json_option _top_json)
261262
# Add range domain to struct and methods
262263
string(APPEND _options_domains_struct "${_option_indent} domain_range_t<${_option_domain_type}> ${_member_name} = ${_range_value_initialize};\n")
263264
list(APPEND _options_has_domain "if (name == \"${_option_name}\") return options_tools::hasDomain(style, options::domain_style::RANGE)")
264-
list(APPEND _options_get_domain "if (name == \"${_option_name}\") return options_tools::getDomain(opt.domains.${_option_name})")
265+
list(APPEND _options_get_enum_domain "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to get domain \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
266+
list(APPEND _options_get_range_domain "if (name == \"${_option_name}\") return options_tools::getRangeDomain(opt.domains.${_option_name})")
265267
list(APPEND _options_increase "if (name == \"${_option_name}\") options_tools::increase(opt.${_option_name}, opt.domains.${_option_name}, up)")
266268
list(APPEND _options_cycle "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to increase \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
267269

@@ -284,14 +286,16 @@ function(_parse_json_option _top_json)
284286
# Add enum domain to struct and methods
285287
string(APPEND _options_domains_struct "${_option_indent} domain_enum_t<${_option_domain_type}> ${_member_name} = ${_enum_value_initialize};\n")
286288
list(APPEND _options_has_domain "if (name == \"${_option_name}\") return options_tools::hasDomain(style, options::domain_style::ENUM)")
287-
list(APPEND _options_get_domain "if (name == \"${_option_name}\") return options_tools::getDomain(opt.domains.${_option_name})")
289+
list(APPEND _options_get_range_domain "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to get domain \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
290+
list(APPEND _options_get_enum_domain "if (name == \"${_option_name}\") return options_tools::getEnumDomain(opt.domains.${_option_name})")
288291
list(APPEND _options_increase "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to cycle \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
289292
list(APPEND _options_cycle "if (name == \"${_option_name}\") options_tools::cycle(opt.${_option_name}, opt.domains.${_option_name})")
290293

291294
# No domain
292295
else()
293296
list(APPEND _options_has_domain "if (name == \"${_option_name}\") return false")
294-
list(APPEND _options_get_domain "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to get domain \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
297+
list(APPEND _options_get_range_domain "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to get domain \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
298+
list(APPEND _options_get_enum_domain "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to get domain \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
295299
list(APPEND _options_increase "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to cycle \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
296300
list(APPEND _options_cycle "if (name == \"${_option_name}\") throw options::incompatible_exception(\"Trying to increase \" + std::string(\"${_option_name}\") + \" with incompatible option\")")
297301
endif()
@@ -324,7 +328,8 @@ function(_parse_json_option _top_json)
324328
set(_options_is_optional ${_options_is_optional} PARENT_SCOPE)
325329
set(_options_reset ${_options_reset} PARENT_SCOPE)
326330
set(_options_has_domain ${_options_has_domain} PARENT_SCOPE)
327-
set(_options_get_domain ${_options_get_domain} PARENT_SCOPE)
331+
set(_options_get_range_domain ${_options_get_range_domain} PARENT_SCOPE)
332+
set(_options_get_enum_domain ${_options_get_enum_domain} PARENT_SCOPE)
328333
set(_options_increase ${_options_increase} PARENT_SCOPE)
329334
set(_options_cycle ${_options_cycle} PARENT_SCOPE)
330335
endfunction()

library/private/options_generated.h.in

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,24 @@ bool hasDomain(std::string_view name, f3d::options::domain_style& style)
138138

139139
//----------------------------------------------------------------------------
140140
/**
141-
* Generated method, see `options::getDomain`
141+
* Generated method, see `options::getEnumDomain`
142142
*/
143-
std::vector<std::string> getDomain(const f3d::options& opt, std::string_view name)
143+
std::vector<std::string> getEnumDomain(const f3d::options& opt, std::string_view name)
144144
{
145145
// clang-format off
146-
${_options_get_domain};
146+
${_options_get_enum_domain};
147+
// clang-format on
148+
else throw options::inexistent_exception("Option " + std::string(name) + " does not exist");
149+
}
150+
151+
//----------------------------------------------------------------------------
152+
/**
153+
* Generated method, see `options::getRangeDomain`
154+
*/
155+
std::pair<std::array<std::string, 2>, std::string> getRangeDomain(const f3d::options& opt, std::string_view name)
156+
{
157+
// clang-format off
158+
${_options_get_range_domain};
147159
// clang-format on
148160
else throw options::inexistent_exception("Option " + std::string(name) + " does not exist");
149161
}

library/private/options_tools.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,24 @@ bool hasDomain(f3d::options::domain_style& styleVar, const f3d::options::domain_
901901
* Get provided domain_range as a string vector
902902
*/
903903
template<typename T>
904-
std::vector<std::string> getDomain(const f3d::options::domain_range_t<T>& domain)
904+
std::pair<std::array<std::string, 2>, std::string> getRangeDomain(const f3d::options::domain_range_t<T>& domain)
905905
{
906-
std::vector<std::string> ret;
907-
ret.emplace_back(format(domain.range[0]));
908-
ret.emplace_back(format(domain.range[1]));
909-
ret.emplace_back(format(domain.increment));
906+
std::pair<std::array<std::string, 2>, std::string> ret;
907+
ret.first[0] = std::move(format(domain.range[0]));
908+
ret.first[1] = std::move(format(domain.range[1]));
909+
ret.second = std::move(format(domain.increment));
910+
return ret;
911+
}
912+
913+
//----------------------------------------------------------------------------
914+
/**
915+
* Get provided domain_range<std::string> as a string vector
916+
*/
917+
std::pair<std::array<std::string, 2>, std::string> getRangeDomain(const f3d::options::domain_range_t<std::string>& domain)
918+
{
919+
std::pair<std::array<std::string, 2>, std::string> ret;
920+
ret.first = domain.range;
921+
ret.second = domain.increment;
910922
return ret;
911923
}
912924

@@ -915,7 +927,7 @@ std::vector<std::string> getDomain(const f3d::options::domain_range_t<T>& domain
915927
* Get provided domain_enum as a string vector
916928
*/
917929
template<typename T>
918-
std::vector<std::string> getDomain(const f3d::options::domain_enum_t<T>& domain)
930+
std::vector<std::string> getEnumDomain(const f3d::options::domain_enum_t<T>& domain)
919931
{
920932
std::vector<std::string> ret;
921933
std::ranges::transform(
@@ -927,7 +939,7 @@ std::vector<std::string> getDomain(const f3d::options::domain_enum_t<T>& domain)
927939
/**
928940
* Get provided domain_enum<std::string> enumeration
929941
*/
930-
std::vector<std::string> getDomain(const f3d::options::domain_enum_t<std::string>& domain)
942+
std::vector<std::string> getEnumDomain(const f3d::options::domain_enum_t<std::string>& domain)
931943
{
932944
return domain.enumeration;
933945
}

library/public/options.h.in

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,20 @@ public:
166166
[[nodiscard]] bool hasDomain(std::string_view name, domain_style& style) const;
167167

168168
/**
169-
* Return a string vector version of the domain of provided option.
170-
* For a range domain, [0] and [1] are min and max respectively, [2] is the increment.
171-
* For a enum domain, the enumeration is provided as is.
172-
* Throw options::incompatible_exception if option has no domain.
169+
* Return a the min, max and increment of the range domain of provided option.
170+
* Provided as a pair containing the min/max as an array and the increment.
171+
* Throw options::incompatible_exception if option doesn't have a range domain.
173172
* Throws an options::inexistent_exception if option does not exist.
174173
*/
175-
[[nodiscard]] std::vector<std::string> getDomain(std::string_view name) const;
174+
[[nodiscard]] std::pair<std::array<std::string, 2>, std::string> getRangeDomain(std::string_view name) const;
175+
176+
/**
177+
* Return a the enumeration of the enum domain of provided option.
178+
* The enumeration is provided as is in string form.
179+
* Throw options::incompatible_exception if option doesn't have an enumeration domain.
180+
* Throws an options::inexistent_exception if option does not exist.
181+
*/
182+
[[nodiscard]] std::vector<std::string> getEnumDomain(std::string_view name) const;
176183

177184
/**
178185
* Increase an option value if it has a range domain, else throws

library/src/interactor_impl.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ interactor& interactor_impl::initCommands()
831831
style == f3d::options::domain_style::ENUM)
832832
{
833833
// recover the enumeration
834-
std::vector<std::string> enumeration = this->Internals->Options.getDomain(args[0]);
834+
std::vector<std::string> enumeration = this->Internals->Options.getEnumDomain(args[0]);
835835

836836
// Transform potential values into found option
837837
std::ranges::transform(enumeration, std::back_inserter(candidates),
@@ -857,7 +857,7 @@ interactor& interactor_impl::initCommands()
857857
style == f3d::options::domain_style::ENUM)
858858
{
859859
// recover the enumeration
860-
std::vector<std::string> enumeration = this->Internals->Options.getDomain(args[0]);
860+
std::vector<std::string> enumeration = this->Internals->Options.getEnumDomain(args[0]);
861861

862862
// Complete the option value if possible
863863
return complNames(args, enumeration, 1);

library/src/options.cxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,15 @@ bool options::hasDomain(std::string_view name, domain_style& style) const
195195
}
196196

197197
//----------------------------------------------------------------------------
198-
std::vector<std::string> options::getDomain(std::string_view name) const
198+
std::pair<std::array<std::string, 2>, std::string> options::getRangeDomain(std::string_view name) const
199199
{
200-
return options_generated::getDomain(*this, name);
200+
return options_generated::getRangeDomain(*this, name);
201+
}
202+
203+
//----------------------------------------------------------------------------
204+
std::vector<std::string> options::getEnumDomain(std::string_view name) const
205+
{
206+
return options_generated::getEnumDomain(*this, name);
201207
}
202208

203209
//----------------------------------------------------------------------------

library/testing/TestSDKOptionsDomains.cxx

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ int TestSDKOptionsDomains([[maybe_unused]] int argc, [[maybe_unused]] char* argv
1818
test.expect<f3d::options::inexistent_exception>(
1919
"hasDomain inexistent", [&]() { std::ignore = opt.hasDomain("inexistent", style); });
2020

21-
// Test getDomain
22-
test("getDomain range", opt.getDomain("scene.animation.speed_factor"), { "0", "2", "0.1" });
23-
test("getDomain enum", opt.getDomain("render.effect.blending.mode"),
21+
// Test getRangeDomain
22+
std::pair<std::array<std::string, 2>, std::string> rangeDomain = opt.getRangeDomain("scene.animation.speed_factor");
23+
test("getRangeDomain range", rangeDomain.first, {"0", "2"});
24+
test("getRangeDomain increment", rangeDomain.second, std::string("0.1"));
25+
test.expect<f3d::options::incompatible_exception>(
26+
"getRangeDomain incompatible", [&]() { std::ignore = opt.getRangeDomain("model.scivis.cells"); });
27+
test.expect<f3d::options::inexistent_exception>(
28+
"getRangeDomain inexistent", [&]() { std::ignore = opt.getRangeDomain("inexistent"); });
29+
30+
// Test getEnumDomain
31+
test("getEnumDomain", opt.getEnumDomain("render.effect.blending.mode"),
2432
{ "none", "ddp", "sort", "sort_cpu", "stochastic" });
2533
test.expect<f3d::options::incompatible_exception>(
26-
"getDomain incompatible", [&]() { std::ignore = opt.getDomain("model.scivis.cells"); });
34+
"getEnumDomain incompatible", [&]() { std::ignore = opt.getEnumDomain("model.scivis.cells"); });
2735
test.expect<f3d::options::inexistent_exception>(
28-
"getDomain inexistent", [&]() { std::ignore = opt.getDomain("inexistent"); });
36+
"getEnumDomain inexistent", [&]() { std::ignore = opt.getEnumDomain("inexistent"); });
2937

3038
// Test increase/decrease
3139

@@ -110,25 +118,64 @@ int TestSDKOptionsDomains([[maybe_unused]] int argc, [[maybe_unused]] char* argv
110118
// render.effect.blending.mode: tested above
111119
// scene.animation.speed_factor: tested above
112120
// render.raytracing.samples: tested above
113-
test("interactor.style domain", opt.getDomain("interactor.style"), {"default", "trackball", "2d"});
114-
test("model.color.opacity domain", opt.getDomain("model.color.opacity"), {"0", "1", "0.05"});
115-
test("model.material.base_ior domain", opt.getDomain("model.material.base_ior"), {"0", "1", "0.05"});
116-
test("model.material.metallic domain", opt.getDomain("model.material.metallic"), {"0", "1", "0.05"});
117-
test("model.material.roughness domain", opt.getDomain("model.material.roughness"), {"0", "1", "0.05"});
118-
test("model.normal.scale domain", opt.getDomain("model.normal.scale"), {"0", "1", "0.05"});
119-
test("model.normal_glyphs.scale domain", opt.getDomain("model.normal_glyphs.scale"), {"0", "10", "0.1"});
120-
test("model.point_sprites.size domain", opt.getDomain("model.point_sprites.size"), {"1", "100", "1"});
121-
test("model.point_sprites.type domain", opt.getDomain("model.point_sprites.type"), {"none", "sphere", "gaussian", "circle", "stddev", "bound","cross"});
122-
test("model.scivis.discretization domain", opt.getDomain("model.scivis.discretization"), {"1", "1024", "5"});
123-
test("render.backface_type domain", opt.getDomain("render.backface_type"), {"visible", "hidden"});
124-
test("render.background.blur.coc domain", opt.getDomain("render.background.blur.coc"), {"0", "100", "5"});
125-
test("render.effect.antialiasing.mode domain", opt.getDomain("render.effect.antialiasing.mode"), {"none", "fxaa", "ssaa", "taa"});
126-
test("render.light.intensity domain", opt.getDomain("render.light.intensity"), {"0", "5", "0.02"});
127-
test("render.line_width domain", opt.getDomain("render.line_width"), {"0", "10", "0.1"});
128-
test("render.point_size domain", opt.getDomain("render.point_size"), {"0", "10", "0.1"});
129-
test("scene.camera.index domain", opt.getDomain("scene.camera.index"), {});
130-
test("ui.backdrop.opacity domain", opt.getDomain("ui.backdrop.opacity"), {"0", "1", "0.05"});
131-
test("ui.scale domain", opt.getDomain("ui.scale"), {"0", "10", "0.1"});
121+
122+
rangeDomain = opt.getRangeDomain("model.color.opacity");
123+
test("model.color.opacity range", rangeDomain.first, {"0", "1"});
124+
test("model.color.opacity increment", rangeDomain.second, std::string("0.05"));
125+
126+
rangeDomain = opt.getRangeDomain("model.material.base_ior");
127+
test("model.material.base_ior range", rangeDomain.first, {"0", "1"});
128+
test("model.material.base_ior increment", rangeDomain.second, std::string("0.05"));
129+
130+
rangeDomain = opt.getRangeDomain("model.material.metallic");
131+
test("model.material.metallic range", rangeDomain.first, {"0", "1"});
132+
test("model.material.metallic increment", rangeDomain.second, std::string("0.05"));
133+
134+
rangeDomain = opt.getRangeDomain("model.material.roughness");
135+
test("model.material.roughness range", rangeDomain.first, {"0", "1"});
136+
test("model.material.roughness increment", rangeDomain.second, std::string("0.05"));
137+
138+
rangeDomain = opt.getRangeDomain("model.normal.scale");
139+
test("model.normal.scale range", rangeDomain.first, {"0", "1"});
140+
test("model.normal.scale increment", rangeDomain.second, std::string("0.05"));
141+
142+
rangeDomain = opt.getRangeDomain("model.normal_glyphs.scale");
143+
test("model.normal_glyphs.scale range", rangeDomain.first, {"0", "10"});
144+
test("model.normal_glyphs.scale increment", rangeDomain.second, std::string("0.1"));
145+
146+
rangeDomain = opt.getRangeDomain("model.scivis.discretization");
147+
test("model.scivis.discretization range", rangeDomain.first, {"1", "1024"});
148+
test("model.scivis.discretization increment", rangeDomain.second, std::string("5"));
149+
150+
rangeDomain = opt.getRangeDomain("render.background.blur.coc");
151+
test("render.background.blur.coc range", rangeDomain.first, {"0", "100"});
152+
test("render.background.blur.coc increment", rangeDomain.second, std::string("5"));
153+
154+
rangeDomain = opt.getRangeDomain("render.light.intensity");
155+
test("render.light.intensity range", rangeDomain.first, {"0", "5"});
156+
test("render.light.intensity increment", rangeDomain.second, std::string("0.02"));
157+
158+
rangeDomain = opt.getRangeDomain("render.line_width");
159+
test("render.line_width range", rangeDomain.first, {"0", "10"});
160+
test("render.line_width increment", rangeDomain.second, std::string("0.1"));
161+
162+
rangeDomain = opt.getRangeDomain("render.point_size");
163+
test("render.point_size range", rangeDomain.first, {"0", "10"});
164+
test("render.point_size increment", rangeDomain.second, std::string("0.1"));
165+
166+
rangeDomain = opt.getRangeDomain("ui.backdrop.opacity");
167+
test("ui.backdrop.opacity range", rangeDomain.first, {"0", "1"});
168+
test("ui.backdrop.opacity increment", rangeDomain.second, std::string("0.05"));
169+
170+
rangeDomain = opt.getRangeDomain("ui.scale");
171+
test("ui.scale range", rangeDomain.first, {"0", "10"});
172+
test("ui.scale increment", rangeDomain.second, std::string("0.1"));
173+
174+
test("interactor.style enum", opt.getEnumDomain("interactor.style"), {"default", "trackball", "2d"});
175+
test("model.point_sprites.type enum", opt.getEnumDomain("model.point_sprites.type"), {"none", "sphere", "gaussian", "circle", "stddev", "bound","cross"});
176+
test("render.backface_type enum", opt.getEnumDomain("render.backface_type"), {"visible", "hidden"});
177+
test("render.effect.antialiasing.mode enum", opt.getEnumDomain("render.effect.antialiasing.mode"), {"none", "fxaa", "ssaa", "taa"});
178+
test("scene.camera.index enum", opt.getEnumDomain("scene.camera.index"), {});
132179
// clang-format on
133180

134181
return test.result();

0 commit comments

Comments
 (0)