diff Framework/Toolbox/GenericToolbox.h @ 1306:fef1ec42a7db broker

Some docs + headers added to CMake for easier VS browsing + tiny predecl
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Mar 2020 10:07:14 +0100
parents 7ec8fea061b9
children fd616c4a5904
line wrap: on
line diff
--- a/Framework/Toolbox/GenericToolbox.h	Wed Mar 04 09:45:38 2020 +0100
+++ b/Framework/Toolbox/GenericToolbox.h	Wed Mar 04 10:07:14 2020 +0100
@@ -29,6 +29,12 @@
 {
   namespace GenericToolbox
   {
+    /**
+    Fast floating point string validation.
+    No trimming applied, so the input must match regex 
+    /^[-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/
+    The following are allowed as edge cases: "" and "-"
+    */
     inline bool LegitDoubleString(const char* text)
     {
       const char* p = text;
@@ -70,6 +76,11 @@
       return true;
     }
 
+    /**
+    Fast integer string validation.
+    No trimming applied, so the input must match regex /^-?[0-9]*$/
+    The following are allowed as edge cases: "" and "-"
+    */
     inline bool LegitIntegerString(const char* text)
     {
       const char* p = text;
@@ -86,6 +97,9 @@
     }
 
     /*
+      Fast string --> double conversion.
+      Must pass the LegitDoubleString test
+
       String to doubles with at most 18 digits
     */
     inline bool StringToDouble(double& r, const char* text)
@@ -210,10 +224,17 @@
       return StringToDouble(r, text.c_str());
     }
 
+    /**
+    Fast string to integer conversion. Leading zeroes and minus are accepted,
+    but a leading + sign is NOT.
+    Must pass the LegitIntegerString function test.
+    In addition, an empty string (or lone minus sign) yields 0.
+    */
+
     template<typename T>
     inline bool StringToInteger(T& r, const char* text)
     {
-      if (!LegitDoubleString(text))
+      if (!LegitIntegerString(text))
         return false;
 
       r = 0;
@@ -244,21 +265,27 @@
     }
 
     /**
-    "rgb(12,23,255)"  --> red, green, blue and returns true
-    "everything else" --> returns false (other values left untouched)
+    if input is "rgb(12,23,255)"  --> function fills `red`, `green` and `blue` and returns true
+    else ("everything else")      --> function returns false and leaves all values untouched
     */
     bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const char* text);
 
     /**
-    See other overload
+    See main overload
     */
     inline bool GetRgbValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, const std::string& text)
     {
       return GetRgbValuesFromString(red, green, blue, text.c_str());
     }
 
+    /**
+    Same as GetRgbValuesFromString
+    */
     bool GetRgbaValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha, const char* text);
 
+    /**
+    Same as GetRgbValuesFromString
+    */
     inline bool GetRgbaValuesFromString(uint8_t& red, uint8_t& green, uint8_t& blue, uint8_t& alpha, const std::string& text)
     {
       return GetRgbaValuesFromString(red, green, blue, alpha, text.c_str());