Skip to content

Commit b892a80

Browse files
authored
Merge pull request #218 from yungyuc/comment/information-for-toggle
Add information for the 3 types of toggles: solid, fixed, and dynamic
2 parents 93b7515 + 6c05205 commit b892a80

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cpp/modmesh/toggle/toggle.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,49 @@ class FixedToggle
215215

216216
}; /* end class FixedToggle */
217217

218+
/**
219+
* The toggle system for modmesh. There are 3 types of toggles:
220+
*
221+
* 1. solid toggles: managed by SolidToggle class. It is the toggles whose value
222+
* is determined during compile time. The value is read-only (const) through
223+
* out the program lifecycle (the process).
224+
*
225+
* The solid toggles have address and can be referenced. They cannot be
226+
* optimized out (unlike macros and constexpr). It could add overhead when
227+
* used in tight loops. The overhead may usually be too low to be noticed,
228+
* but sometimes one needs to be careful about it.
229+
*
230+
* 2. fixed toggles: managed by FixedToggle class. It is the toggles whose name
231+
* is determined during compile time. The value can be changed during
232+
* runtime.
233+
*
234+
* Because the names are determined during compile time, when accessing the
235+
* toggles, no table lookup is needed. The address of the toggle variables
236+
* has been determined by the compiler and linker.
237+
*
238+
* The runtime cost of fixed toggles is the same as solid toggles. It may
239+
* be used in tight loops. Just becareful about the potential runtime
240+
* overhead.
241+
*
242+
* 3. dynamic toggles: managed by DynamicToggleTable. The toggles are
243+
* hierarchical and the names and values can be added, removed, and modified
244+
* during runtime. The value needs to use limited data types: bool, int8,
245+
* int16, int32, int64, real, and string. It is intentional not to support
246+
* unsigned integers.
247+
*
248+
* Accessing dynamic toggles requires table lookup and string comparison. It
249+
* is slow but flexible.
250+
*
251+
* To access the dynamic toggles from C++, the data type of the toggle
252+
* The hierarchical access (from C++) uses ".", like:
253+
*
254+
* tg.get_int8("top_level.second_level.key_name")
255+
*
256+
* In Python, the wrapper can determine the type dynamically, and the
257+
* hierarchical access may use attribute syntax:
258+
*
259+
* tg.top_level.second_level.key_name = value
260+
*/
218261
class Toggle
219262
{
220263

0 commit comments

Comments
 (0)