diff --git a/etk/Color.cpp b/etk/Color.cpp index 0f6e5ce..341ecb0 100644 --- a/etk/Color.cpp +++ b/etk/Color.cpp @@ -15,9 +15,6 @@ #include #include -#undef __class__ -#define __class__ "Color" - typedef struct { const char * colorName; etk::Color<> color; diff --git a/etk/Color.h b/etk/Color.h index 7bef00c..38b08d4 100644 --- a/etk/Color.h +++ b/etk/Color.h @@ -20,20 +20,21 @@ namespace etk { * For example : * - Graphic application use: * - Image in 3/4 bytes for rgb(a) - * - Color description in char : '#F6780FFF' or the equivalent number:0xF6780FFF + * - Color description in char : '\#F6780FFF' or the equivalent number:0xF6780FFF * - middleware will mainely use a the 4 separate value with 1 byte for each. * - graphic interface (openGL) store image in 1/2/3/4 bytes color and interpolate it in 'n' float. And note that the user color is sored in float. * * Then with this class we abstract the transformation format and set an easy same way to use the color independing of the developpement level. * - * Some of the basic color is defined in the namespace: [namespace[etk::color]]. + * Some of the basic color is defined in the namespace: @ref etk::color. * - * @template-param MY_TYPE Type of the internal template value. The generic value is uint8_t and float + * @param[in] MY_TYPE Type of the internal template value. The generic value is uint8_t and float + * @param[in] MY_TYPE_SIZE Number of value in the color */ template class Color { public: - static const Color emptyColor; // to auto fill with no data in all case - static const MY_TYPE defaultAlpha; + static const Color emptyColor; //!< To auto fill with no data in all case + static const MY_TYPE defaultAlpha; //!< Default alpha value private: MY_TYPE m_element[MY_TYPE_SIZE]; //!< all the color. public: @@ -51,15 +52,27 @@ namespace etk { Color(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b, MY_TYPE _a) { set(_r, _g, _b, _a); }; - //! @previous + /** + * @brief Contructor with request initialisation. + * @param[in] _r Red color. + * @param[in] _g Green color. + * @param[in] _b Blue color. + */ Color(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b) { set(_r, _g, _b); }; - //! @previous + /** + * @brief Contructor with request initialisation. + * @param[in] _r Red color. + * @param[in] _g Green color. + */ Color(MY_TYPE _r, MY_TYPE _g) { set(_r, _g); }; - //! @previous + /** + * @brief Contructor with request initialisation. + * @param[in] _r Red color. + */ Color(MY_TYPE _r) { set(_r); }; @@ -80,7 +93,7 @@ namespace etk { * @return reference on this element. */ Color& operator=(const etk::Color& _input) { - for (size_t iii=0; iii& _obj) const { - for (size_t iii=0; iii& _obj) const { - for (size_t iii=0; iii= 1) { m_element[0] = _r; @@ -154,7 +172,11 @@ namespace etk { m_element[3] = defaultAlpha; } }; - //! @previous + /** + * @brief Set the specified color elements. + * @param[in] _r Red color. + * @param[in] _g Green color. + */ void set(MY_TYPE _r, MY_TYPE _g) { if (MY_TYPE_SIZE >= 1) { m_element[0] = _r; @@ -169,7 +191,10 @@ namespace etk { m_element[3] = defaultAlpha; } }; - //! @previous + /** + * @brief Set the specified color elements. + * @param[in] _r Red color. + */ void set(MY_TYPE _r) { if (MY_TYPE_SIZE >= 1) { m_element[0] = _r; @@ -282,9 +307,11 @@ namespace etk { m_element[3] = MY_TYPE(_a); } }; - /* **************************************************** - * += operator - *****************************************************/ + /** + * @brief Operator+= Addition an other etk::color with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector additionned + */ const etk::Color& operator+= (const etk::Color& _obj) { if (MY_TYPE_SIZE >= 1) { m_element[0] += _obj.m_element[0]; @@ -300,18 +327,22 @@ namespace etk { } return *this; } - /* **************************************************** - * + operator - *****************************************************/ + /** + * @brief Operator+ Addition an other etk::color with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ etk::Color operator+ (const etk::Color& _obj) const { etk::Color tmpp(*this); tmpp += _obj; return tmpp; } - /* **************************************************** - * *= operator - *****************************************************/ - const etk::Color& operator*= (const etk::Color& _obj) { + /** + * @brief Operator*= Multiply 2 color together + * @param[in] _obj Reference on the external object + * @return Local reference of the vector + */ + etk::Color& operator*= (const etk::Color& _obj) { if (MY_TYPE_SIZE >= 1) { m_element[0] *= _obj.m_element[0]; } @@ -326,7 +357,12 @@ namespace etk { } return *this; } - const etk::Color& operator*= (const MY_TYPE _val) { + /** + * @brief Operator*= Multiply the color With a specific value + * @param[in] _val Value to multiply the color + * @return Local reference of the vector + */ + etk::Color& operator*= (const MY_TYPE _val) { if (MY_TYPE_SIZE >= 1) { m_element[0] *= _val; } @@ -341,28 +377,72 @@ namespace etk { } return *this; } - /* **************************************************** - * * operator - *****************************************************/ + /** + * @brief Operator*= Multiply 2 color together + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ etk::Color operator* (const etk::Color& _obj) const { etk::Color tmpp(*this); tmpp *= _obj; return tmpp; } + /** + * @brief Operator*= Multiply the color With a specific value + * @param[in] _val Value to multiply the color + * @return New vector containing the value + */ etk::Color operator* (const MY_TYPE _val) const { etk::Color tmpp(*this); tmpp *= _val; return tmpp; } }; + + /** + * @brief Get a color value started with a "#" + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithSharp(const std::string& _input); + /** + * @brief Get a color value started with a "rgb()" converted in uint8 + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithRGBGen(const std::string& _input); + /** + * @brief Get a color value started with a "rgb()" keep in double + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithRGB(const std::string& _input); + /** + * @brief Get a color value started with a "rgb()" converted in uint32 + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithRGBUnsigned32(const std::string& _input); + /** + * @brief Get a color value started with a "rgb()" converted in uint16 + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithRGBUnsigned16(const std::string& _input); + /** + * @brief Get a color value started with a "rgb()" converted in uint6 + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringStartWithRGBUnsigned8(const std::string& _input); + /** + * @brief Get a color value started with a "named" converted in uint8 like red, geen ... + * @param[in] _input String to parse + * @return Value parsed + */ etk::Color parseStringColorNamed(const std::string& _input); + //! @not_in_doc template<> uint32_t Color::get() const; template uint32_t Color::get() const { @@ -565,7 +645,7 @@ namespace etk { } //! @not_in_doc template std::ostream& operator <<(std::ostream& _os, const std::vector >& _obj) { - for (size_t iii = 0; iii < _obj.size(); ++iii) { + for (size_t iii = 0; iii < _obj.size();iii) { if (iii != 0) { _os << " "; } @@ -579,153 +659,153 @@ namespace etk { */ namespace color { extern const Color<> none; //!< No color (alpha = 0) - extern const Color<> aliceBlue; //!< ++ [color=aliceBlue] aliceBlue color [/color] ++ - extern const Color<> antiqueWhite; //!< ++ [color=antiqueWhite] antiqueWhite color [/color] ++ - extern const Color<> aqua; //!< ++ [color=aqua] aqua color [/color] ++ - extern const Color<> aquamarine; //!< ++ [color=aquamarine] aquamarine color [/color] ++ - extern const Color<> azure; //!< ++ [color=azure] azure color [/color] ++ - extern const Color<> beige; //!< ++ [color=beige] beige color [/color] ++ - extern const Color<> bisque; //!< ++ [color=bisque] bisque color [/color] ++ - extern const Color<> black; //!< ++ [color=black] black color [/color] ++ - extern const Color<> blanchedAlmond; //!< ++ [color=blanchedAlmond] blanchedAlmond color [/color] ++ - extern const Color<> blue; //!< ++ [color=blue] blue color [/color] ++ - extern const Color<> blueViolet; //!< ++ [color=blueViolet] blueViolet color [/color] ++ - extern const Color<> brown; //!< ++ [color=brown] brown color [/color] ++ - extern const Color<> burlyWood; //!< ++ [color=burlyWood] burlyWood color [/color] ++ - extern const Color<> cadetBlue; //!< ++ [color=cadetBlue] cadetBlue color [/color] ++ - extern const Color<> chartreuse; //!< ++ [color=chartreuse] chartreuse color [/color] ++ - extern const Color<> chocolate; //!< ++ [color=chocolate] chocolate color [/color] ++ - extern const Color<> coral; //!< ++ [color=coral] coral color [/color] ++ - extern const Color<> cornflowerBlue; //!< ++ [color=cornflowerBlue] cornflowerBlue color [/color] ++ - extern const Color<> cornsilk; //!< ++ [color=cornsilk] cornsilk color [/color] ++ - extern const Color<> crimson; //!< ++ [color=crimson] crimson color [/color] ++ - extern const Color<> cyan; //!< ++ [color=cyan] cyan color [/color] ++ - extern const Color<> darkBlue; //!< ++ [color=darkBlue] darkBlue color [/color] ++ - extern const Color<> darkCyan; //!< ++ [color=darkCyan] darkCyan color [/color] ++ - extern const Color<> darkGoldenRod; //!< ++ [color=darkGoldenRod] darkGoldenRod color [/color] ++ - extern const Color<> darkGray; //!< ++ [color=darkGray] darkGray color [/color] ++ - extern const Color<> darkGrey; //!< ++ [color=darkGrey] darkGrey color [/color] ++ - extern const Color<> darkGreen; //!< ++ [color=darkGreen] darkGreen color [/color] ++ - extern const Color<> darkKhaki; //!< ++ [color=darkKhaki] darkKhaki color [/color] ++ - extern const Color<> darkMagenta; //!< ++ [color=darkMagenta] darkMagenta color [/color] ++ - extern const Color<> darkOliveGreen; //!< ++ [color=darkOliveGreen] darkOliveGreen color [/color] ++ - extern const Color<> darkorange; //!< ++ [color=darkorange] darkorange color [/color] ++ - extern const Color<> darkOrchid; //!< ++ [color=darkOrchid] darkOrchid color [/color] ++ - extern const Color<> darkRed; //!< ++ [color=darkRed] darkRed color [/color] ++ - extern const Color<> darkSalmon; //!< ++ [color=darkSalmon] darkSalmon color [/color] ++ - extern const Color<> darkSeaGreen; //!< ++ [color=darkSeaGreen] darkSeaGreen color [/color] ++ - extern const Color<> darkSlateBlue; //!< ++ [color=darkSlateBlue] darkSlateBlue color [/color] ++ - extern const Color<> darkSlateGray; //!< ++ [color=darkSlateGray] darkSlateGray color [/color] ++ - extern const Color<> darkSlateGrey; //!< ++ [color=darkSlateGrey] darkSlateGrey color [/color] ++ - extern const Color<> darkTurquoise; //!< ++ [color=darkTurquoise] darkTurquoise color [/color] ++ - extern const Color<> darkViolet; //!< ++ [color=darkViolet] darkViolet color [/color] ++ - extern const Color<> deepPink; //!< ++ [color=deepPink] deepPink color [/color] ++ - extern const Color<> deepSkyBlue; //!< ++ [color=deepSkyBlue] deepSkyBlue color [/color] ++ - extern const Color<> dimGray; //!< ++ [color=dimGray] dimGray color [/color] ++ - extern const Color<> dimGrey; //!< ++ [color=dimGrey] dimGrey color [/color] ++ - extern const Color<> dodgerBlue; //!< ++ [color=dodgerBlue] dodgerBlue color [/color] ++ - extern const Color<> fireBrick; //!< ++ [color=fireBrick] fireBrick color [/color] ++ - extern const Color<> floralWhite; //!< ++ [color=floralWhite] floralWhite color [/color] ++ - extern const Color<> forestGreen; //!< ++ [color=forestGreen] forestGreen color [/color] ++ - extern const Color<> fuchsia; //!< ++ [color=fuchsia] fuchsia color [/color] ++ - extern const Color<> gainsboro; //!< ++ [color=gainsboro] gainsboro color [/color] ++ - extern const Color<> ghostWhite; //!< ++ [color=ghostWhite] ghostWhite color [/color] ++ - extern const Color<> gold; //!< ++ [color=gold] gold color [/color] ++ - extern const Color<> goldenRod; //!< ++ [color=goldenRod] goldenRod color [/color] ++ - extern const Color<> gray; //!< ++ [color=gray] gray color [/color] ++ - extern const Color<> grey; //!< ++ [color=grey] grey color [/color] ++ - extern const Color<> green; //!< ++ [color=green] green color [/color] ++ - extern const Color<> greenYellow; //!< ++ [color=greenYellow] greenYellow color [/color] ++ - extern const Color<> honeyDew; //!< ++ [color=honeyDew] honeyDew color [/color] ++ - extern const Color<> hotPink; //!< ++ [color=hotPink] hotPink color [/color] ++ - extern const Color<> indianRed; //!< ++ [color=indianRed] indianRed color [/color] ++ - extern const Color<> indigo; //!< ++ [color=indigo] indigo color [/color] ++ - extern const Color<> ivory; //!< ++ [color=ivory] ivory color [/color] ++ - extern const Color<> khaki; //!< ++ [color=khaki] khaki color [/color] ++ - extern const Color<> lavender; //!< ++ [color=lavender] lavender color [/color] ++ - extern const Color<> lavenderBlush; //!< ++ [color=lavenderBlush] lavenderBlush color [/color] ++ - extern const Color<> lawnGreen; //!< ++ [color=lawnGreen] lawnGreen color [/color] ++ - extern const Color<> lemonChiffon; //!< ++ [color=lemonChiffon] lemonChiffon color [/color] ++ - extern const Color<> lightBlue; //!< ++ [color=lightBlue] lightBlue color [/color] ++ - extern const Color<> lightCoral; //!< ++ [color=lightCoral] lightCoral color [/color] ++ - extern const Color<> lightCyan; //!< ++ [color=lightCyan] lightCyan color [/color] ++ - extern const Color<> lightGoldenRodYellow; //!< ++ [color=lightGoldenRodYellow] lightGoldenRodYellow color [/color] ++ - extern const Color<> lightGray; //!< ++ [color=lightGray] lightGray color [/color] ++ - extern const Color<> lightGrey; //!< ++ [color=lightGrey] lightGrey color [/color] ++ - extern const Color<> lightGreen; //!< ++ [color=lightGreen] lightGreen color [/color] ++ - extern const Color<> lightPink; //!< ++ [color=lightPink] lightPink color [/color] ++ - extern const Color<> lightSalmon; //!< ++ [color=lightSalmon] lightSalmon color [/color] ++ - extern const Color<> lightSeaGreen; //!< ++ [color=lightSeaGreen] lightSeaGreen color [/color] ++ - extern const Color<> lightSkyBlue; //!< ++ [color=lightSkyBlue] lightSkyBlue color [/color] ++ - extern const Color<> lightSlateGray; //!< ++ [color=lightSlateGray] lightSlateGray color [/color] ++ - extern const Color<> lightSlateGrey; //!< ++ [color=lightSlateGrey] lightSlateGrey color [/color] ++ - extern const Color<> lightSteelBlue; //!< ++ [color=lightSteelBlue] lightSteelBlue color [/color] ++ - extern const Color<> lightYellow; //!< ++ [color=lightYellow] lightYellow color [/color] ++ - extern const Color<> lime; //!< ++ [color=lime] lime color [/color] ++ - extern const Color<> limeGreen; //!< ++ [color=limeGreen] limeGreen color [/color] ++ - extern const Color<> linen; //!< ++ [color=linen] linen color [/color] ++ - extern const Color<> magenta; //!< ++ [color=magenta] magenta color [/color] ++ - extern const Color<> maroon; //!< ++ [color=maroon] maroon color [/color] ++ - extern const Color<> mediumAquaMarine; //!< ++ [color=mediumAquaMarine] mediumAquaMarine color [/color] ++ - extern const Color<> mediumBlue; //!< ++ [color=mediumBlue] mediumBlue color [/color] ++ - extern const Color<> mediumOrchid; //!< ++ [color=mediumOrchid] mediumOrchid color [/color] ++ - extern const Color<> mediumPurple; //!< ++ [color=mediumPurple] mediumPurple color [/color] ++ - extern const Color<> mediumSeaGreen; //!< ++ [color=mediumSeaGreen] mediumSeaGreen color [/color] ++ - extern const Color<> mediumSlateBlue; //!< ++ [color=mediumSlateBlue] mediumSlateBlue color [/color] ++ - extern const Color<> mediumSpringGreen; //!< ++ [color=mediumSpringGreen] mediumSpringGreen color [/color] ++ - extern const Color<> mediumTurquoise; //!< ++ [color=mediumTurquoise] mediumTurquoise color [/color] ++ - extern const Color<> mediumVioletRed; //!< ++ [color=mediumVioletRed] mediumVioletRed color [/color] ++ - extern const Color<> midnightBlue; //!< ++ [color=midnightBlue] midnightBlue color [/color] ++ - extern const Color<> mintCream; //!< ++ [color=mintCream] mintCream color [/color] ++ - extern const Color<> mistyRose; //!< ++ [color=mistyRose] mistyRose color [/color] ++ - extern const Color<> moccasin; //!< ++ [color=moccasin] moccasin color [/color] ++ - extern const Color<> navajoWhite; //!< ++ [color=navajoWhite] navajoWhite color [/color] ++ - extern const Color<> navy; //!< ++ [color=navy] navy color [/color] ++ - extern const Color<> oldLace; //!< ++ [color=oldLace] oldLace color [/color] ++ - extern const Color<> olive; //!< ++ [color=olive] olive color [/color] ++ - extern const Color<> oliveDrab; //!< ++ [color=oliveDrab] oliveDrab color [/color] ++ - extern const Color<> orange; //!< ++ [color=orange] orange color [/color] ++ - extern const Color<> orangeRed; //!< ++ [color=orangeRed] orangeRed color [/color] ++ - extern const Color<> orchid; //!< ++ [color=orchid] orchid color [/color] ++ - extern const Color<> paleGoldenRod; //!< ++ [color=paleGoldenRod] paleGoldenRod color [/color] ++ - extern const Color<> paleGreen; //!< ++ [color=paleGreen] paleGreen color [/color] ++ - extern const Color<> paleTurquoise; //!< ++ [color=paleTurquoise] paleTurquoise color [/color] ++ - extern const Color<> paleVioletRed; //!< ++ [color=paleVioletRed] paleVioletRed color [/color] ++ - extern const Color<> papayaWhip; //!< ++ [color=papayaWhip] papayaWhip color [/color] ++ - extern const Color<> peachPuff; //!< ++ [color=peachPuff] peachPuff color [/color] ++ - extern const Color<> peru; //!< ++ [color=peru] peru color [/color] ++ - extern const Color<> pink; //!< ++ [color=pink] pink color [/color] ++ - extern const Color<> plum; //!< ++ [color=plum] plum color [/color] ++ - extern const Color<> powderBlue; //!< ++ [color=powderBlue] powderBlue color [/color] ++ - extern const Color<> purple; //!< ++ [color=purple] purple color [/color] ++ - extern const Color<> red; //!< ++ [color=red] red color [/color] ++ - extern const Color<> rosyBrown; //!< ++ [color=rosyBrown] rosyBrown color [/color] ++ - extern const Color<> royalBlue; //!< ++ [color=royalBlue] royalBlue color [/color] ++ - extern const Color<> saddleBrown; //!< ++ [color=saddleBrown] saddleBrown color [/color] ++ - extern const Color<> salmon; //!< ++ [color=salmon] salmon color [/color] ++ - extern const Color<> sandyBrown; //!< ++ [color=sandyBrown] sandyBrown color [/color] ++ - extern const Color<> seaGreen; //!< ++ [color=seaGreen] seaGreen color [/color] ++ - extern const Color<> seaShell; //!< ++ [color=seaShell] seaShell color [/color] ++ - extern const Color<> sienna; //!< ++ [color=sienna] sienna color [/color] ++ - extern const Color<> silver; //!< ++ [color=silver] silver color [/color] ++ - extern const Color<> skyBlue; //!< ++ [color=skyBlue] skyBlue color [/color] ++ - extern const Color<> slateBlue; //!< ++ [color=slateBlue] slateBlue color [/color] ++ - extern const Color<> slateGray; //!< ++ [color=slateGray] slateGray color [/color] ++ - extern const Color<> slateGrey; //!< ++ [color=slateGrey] slateGrey color [/color] ++ - extern const Color<> snow; //!< ++ [color=snow] snow color [/color] ++ - extern const Color<> springGreen; //!< ++ [color=springGreen] springGreen color [/color] ++ - extern const Color<> steelBlue; //!< ++ [color=steelBlue] steelBlue color [/color] ++ - extern const Color<> tan; //!< ++ [color=tan] tan color [/color] ++ - extern const Color<> teal; //!< ++ [color=teal] teal color [/color] ++ - extern const Color<> thistle; //!< ++ [color=thistle] thistle color [/color] ++ - extern const Color<> tomato; //!< ++ [color=tomato] tomato color [/color] ++ - extern const Color<> turquoise; //!< ++ [color=turquoise] turquoise color [/color] ++ - extern const Color<> violet; //!< ++ [color=violet] violet color [/color] ++ - extern const Color<> wheat; //!< ++ [color=wheat] wheat color [/color] ++ - extern const Color<> white; //!< ++ [color=white] white color [/color] ++ - extern const Color<> whiteSmoke; //!< ++ [color=whiteSmoke] whiteSmoke color [/color] ++ - extern const Color<> yellow; //!< ++ [color=yellow] yellow color [/color] ++ - extern const Color<> yellowGreen; //!< ++ [color=yellowGreen] yellowGreen color [/color] ++ + extern const Color<> aliceBlue; //!< - aliceBlue color + extern const Color<> antiqueWhite; //!< - antiqueWhite color + extern const Color<> aqua; //!< - aqua color + extern const Color<> aquamarine; //!< - aquamarine color + extern const Color<> azure; //!< - azure color + extern const Color<> beige; //!< - beige color + extern const Color<> bisque; //!< - bisque color + extern const Color<> black; //!< - black color + extern const Color<> blanchedAlmond; //!< - blanchedAlmond color + extern const Color<> blue; //!< - blue color + extern const Color<> blueViolet; //!< - blueViolet color + extern const Color<> brown; //!< - brown color + extern const Color<> burlyWood; //!< - burlyWood color + extern const Color<> cadetBlue; //!< - cadetBlue color + extern const Color<> chartreuse; //!< - chartreuse color + extern const Color<> chocolate; //!< - chocolate color + extern const Color<> coral; //!< - coral color + extern const Color<> cornflowerBlue; //!< - cornflowerBlue color + extern const Color<> cornsilk; //!< - cornsilk color + extern const Color<> crimson; //!< - crimson color + extern const Color<> cyan; //!< - cyan color + extern const Color<> darkBlue; //!< - darkBlue color + extern const Color<> darkCyan; //!< - darkCyan color + extern const Color<> darkGoldenRod; //!< - darkGoldenRod color + extern const Color<> darkGray; //!< - darkGray color + extern const Color<> darkGrey; //!< - darkGrey color + extern const Color<> darkGreen; //!< - darkGreen color + extern const Color<> darkKhaki; //!< - darkKhaki color + extern const Color<> darkMagenta; //!< - darkMagenta color + extern const Color<> darkOliveGreen; //!< - darkOliveGreen color + extern const Color<> darkorange; //!< - darkorange color + extern const Color<> darkOrchid; //!< - darkOrchid color + extern const Color<> darkRed; //!< - darkRed color + extern const Color<> darkSalmon; //!< - darkSalmon color + extern const Color<> darkSeaGreen; //!< - darkSeaGreen color + extern const Color<> darkSlateBlue; //!< - darkSlateBlue color + extern const Color<> darkSlateGray; //!< - darkSlateGray color + extern const Color<> darkSlateGrey; //!< - darkSlateGrey color + extern const Color<> darkTurquoise; //!< - darkTurquoise color + extern const Color<> darkViolet; //!< - darkViolet color + extern const Color<> deepPink; //!< - deepPink color + extern const Color<> deepSkyBlue; //!< - deepSkyBlue color + extern const Color<> dimGray; //!< - dimGray color + extern const Color<> dimGrey; //!< - dimGrey color + extern const Color<> dodgerBlue; //!< - dodgerBlue color + extern const Color<> fireBrick; //!< - fireBrick color + extern const Color<> floralWhite; //!< - floralWhite color + extern const Color<> forestGreen; //!< - forestGreen color + extern const Color<> fuchsia; //!< - fuchsia color + extern const Color<> gainsboro; //!< - gainsboro color + extern const Color<> ghostWhite; //!< - ghostWhite color + extern const Color<> gold; //!< - gold color + extern const Color<> goldenRod; //!< - goldenRod color + extern const Color<> gray; //!< - gray color + extern const Color<> grey; //!< - grey color + extern const Color<> green; //!< - green color + extern const Color<> greenYellow; //!< - greenYellow color + extern const Color<> honeyDew; //!< - honeyDew color + extern const Color<> hotPink; //!< - hotPink color + extern const Color<> indianRed; //!< - indianRed color + extern const Color<> indigo; //!< - indigo color + extern const Color<> ivory; //!< - ivory color + extern const Color<> khaki; //!< - khaki color + extern const Color<> lavender; //!< - lavender color + extern const Color<> lavenderBlush; //!< - lavenderBlush color + extern const Color<> lawnGreen; //!< - lawnGreen color + extern const Color<> lemonChiffon; //!< - lemonChiffon color + extern const Color<> lightBlue; //!< - lightBlue color + extern const Color<> lightCoral; //!< - lightCoral color + extern const Color<> lightCyan; //!< - lightCyan color + extern const Color<> lightGoldenRodYellow; //!< - lightGoldenRodYellow color + extern const Color<> lightGray; //!< - lightGray color + extern const Color<> lightGrey; //!< - lightGrey color + extern const Color<> lightGreen; //!< - lightGreen color + extern const Color<> lightPink; //!< - lightPink color + extern const Color<> lightSalmon; //!< - lightSalmon color + extern const Color<> lightSeaGreen; //!< - lightSeaGreen color + extern const Color<> lightSkyBlue; //!< - lightSkyBlue color + extern const Color<> lightSlateGray; //!< - lightSlateGray color + extern const Color<> lightSlateGrey; //!< - lightSlateGrey color + extern const Color<> lightSteelBlue; //!< - lightSteelBlue color + extern const Color<> lightYellow; //!< - lightYellow color + extern const Color<> lime; //!< - lime color + extern const Color<> limeGreen; //!< - limeGreen color + extern const Color<> linen; //!< - linen color + extern const Color<> magenta; //!< - magenta color + extern const Color<> maroon; //!< - maroon color + extern const Color<> mediumAquaMarine; //!< - mediumAquaMarine color + extern const Color<> mediumBlue; //!< - mediumBlue color + extern const Color<> mediumOrchid; //!< - mediumOrchid color + extern const Color<> mediumPurple; //!< - mediumPurple color + extern const Color<> mediumSeaGreen; //!< - mediumSeaGreen color + extern const Color<> mediumSlateBlue; //!< - mediumSlateBlue color + extern const Color<> mediumSpringGreen; //!< - mediumSpringGreen color + extern const Color<> mediumTurquoise; //!< - mediumTurquoise color + extern const Color<> mediumVioletRed; //!< - mediumVioletRed color + extern const Color<> midnightBlue; //!< - midnightBlue color + extern const Color<> mintCream; //!< - mintCream color + extern const Color<> mistyRose; //!< - mistyRose color + extern const Color<> moccasin; //!< - moccasin color + extern const Color<> navajoWhite; //!< - navajoWhite color + extern const Color<> navy; //!< - navy color + extern const Color<> oldLace; //!< - oldLace color + extern const Color<> olive; //!< - olive color + extern const Color<> oliveDrab; //!< - oliveDrab color + extern const Color<> orange; //!< - orange color + extern const Color<> orangeRed; //!< - orangeRed color + extern const Color<> orchid; //!< - orchid color + extern const Color<> paleGoldenRod; //!< - paleGoldenRod color + extern const Color<> paleGreen; //!< - paleGreen color + extern const Color<> paleTurquoise; //!< - paleTurquoise color + extern const Color<> paleVioletRed; //!< - paleVioletRed color + extern const Color<> papayaWhip; //!< - papayaWhip color + extern const Color<> peachPuff; //!< - peachPuff color + extern const Color<> peru; //!< - peru color + extern const Color<> pink; //!< - pink color + extern const Color<> plum; //!< - plum color + extern const Color<> powderBlue; //!< - powderBlue color + extern const Color<> purple; //!< - purple color + extern const Color<> red; //!< - red color + extern const Color<> rosyBrown; //!< - rosyBrown color + extern const Color<> royalBlue; //!< - royalBlue color + extern const Color<> saddleBrown; //!< - saddleBrown color + extern const Color<> salmon; //!< - salmon color + extern const Color<> sandyBrown; //!< - sandyBrown color + extern const Color<> seaGreen; //!< - seaGreen color + extern const Color<> seaShell; //!< - seaShell color + extern const Color<> sienna; //!< - sienna color + extern const Color<> silver; //!< - silver color + extern const Color<> skyBlue; //!< - skyBlue color + extern const Color<> slateBlue; //!< - slateBlue color + extern const Color<> slateGray; //!< - slateGray color + extern const Color<> slateGrey; //!< - slateGrey color + extern const Color<> snow; //!< - snow color + extern const Color<> springGreen; //!< - springGreen color + extern const Color<> steelBlue; //!< - steelBlue color + extern const Color<> tan; //!< - tan color + extern const Color<> teal; //!< - teal color + extern const Color<> thistle; //!< - thistle color + extern const Color<> tomato; //!< - tomato color + extern const Color<> turquoise; //!< - turquoise color + extern const Color<> violet; //!< - violet color + extern const Color<> wheat; //!< - wheat color + extern const Color<> white; //!< - white color + extern const Color<> whiteSmoke; //!< - whiteSmoke color + extern const Color<> yellow; //!< - yellow color + extern const Color<> yellowGreen; //!< - yellowGreen color }; }; diff --git a/etk/Hash.h b/etk/Hash.h index 9e084e5..c662f82 100644 --- a/etk/Hash.h +++ b/etk/Hash.h @@ -10,10 +10,6 @@ #pragma once -#undef __class__ -#define __class__ "etk::Hash" - - namespace etk { /** * @brief internel data of the [class[etk::hash]] class, it contain @@ -39,13 +35,17 @@ namespace etk { * @brief Hash table tamplate is a simple classical hash interface. * A hash table is a equivalent of the dictionary in python, this is a * simple interfaace between a name and a value: - * :** "name" : 19 - * :** "name 2" : 99 + * - "name" : 19 + * - "name 2" : 99 * - * [note]The name is unique and the value is what you want.[/note] + * @note The name is unique and the value is what you want + * + * @todo check if something ele exist in the STD. (not the std::map and the std::unordered_map + * + * @note The index are all time availlable since they are created. The order is the the one created * * A simple example of use: - * [code style=c++] + * @code{.cpp} * // Create a integer hash table * Hash myValue; * // add some element (note add and set is the same function) @@ -59,7 +59,7 @@ namespace etk { * myValue.remove("plop"); * //Clean all the table: * myValue.clear(); - * [/code] + * @endcode */ template class Hash { private: @@ -84,10 +84,10 @@ namespace etk { * @note It does not delete pointer if your value is a pointer type... */ void clear() { - for (size_t iii = 0; iii < m_data.size(); ++iii) { - if (m_data[iii] != NULL) { - delete(m_data[iii]); - m_data[iii]=NULL; + for (auto &it : m_data) { + if (it != nullptr) { + delete(it); + it=nullptr; } } m_data.clear(); @@ -99,7 +99,7 @@ namespace etk { */ int64_t getId(const std::string& _key) const { for (size_t iii=0; iiim_key << "' with '" << _key << "'" ); if (m_data[iii]->m_key == _key) { return iii; @@ -111,7 +111,7 @@ namespace etk { } /** * @brief Check if an element exist or not - * @param[in] _key Name of the hash requested + * @param[in] _name Name of the hash requested * @return true if the element exist */ bool exist(const std::string& _name) const { @@ -160,7 +160,7 @@ namespace etk { int64_t elementId = getId(_key); if (elementId <0) { HashData* tmp = new HashData(_key, _value); - if (NULL == tmp) { + if (tmp == nullptr) { //TK_ERROR("allocation error in Hash table : '" << _key << "'"); return; } @@ -170,7 +170,10 @@ namespace etk { m_data[elementId]->m_value = _value; } /** - * @previous + * @brief Set an element value + * @note add and set is the same function. + * @param[in] _key Name of the value to set in the hash table. + * @param[in] _value Value to set in the hash table. */ void set(const std::string& _key, const MY_TYPE& _value) { add(_key, _value); @@ -186,7 +189,7 @@ namespace etk { return; } delete(m_data[elementId]); - m_data[elementId] = NULL; + m_data[elementId] = nullptr; m_data.erase(m_data.begin()+elementId); } /** @@ -206,7 +209,10 @@ namespace etk { return getValue(_pos); } /** - * @previous + * @brief get an element with his id. + * @param[in] _pos Position on the element in the hash table. + * @return requested element at this position. + * @note this is a dangerous use of the hash table. Maybe you will use a simple vector. */ const MY_TYPE& operator[] (size_t _pos) const { return getValue(_pos); @@ -231,16 +237,16 @@ namespace etk { */ std::vector getKeys() const { std::vector keys; - for (size_t iii = 0; iii < m_data.size(); ++iii) { - if (m_data[iii] != NULL) { - keys.push_back(m_data[iii]->m_key); + for (auto &it : m_data) { + if (it != nullptr) { + keys.push_back(it->m_key); } } return keys; } /** * @brief Get a value of the hash table at a specific position. - * @param[in] _posPosition of the element in the hash table. + * @param[in] _pos of the element in the hash table. * @return Value availlable at this position. */ const MY_TYPE& getValue(size_t _pos) const { @@ -253,7 +259,7 @@ namespace etk { return m_data[_pos]->m_value; } /** - * @previous + * @copydoc getValue (size_t) */ MY_TYPE& getValue(size_t _pos) { // NOTE :Do not change log level, this generate error only in debug mode @@ -265,8 +271,5 @@ namespace etk { return m_data[_pos]->m_value; } }; -}; - -#undef __class__ -#define __class__ NULL +} diff --git a/etk/Noise.cpp b/etk/Noise.cpp index 9c51a3e..2757dc2 100644 --- a/etk/Noise.cpp +++ b/etk/Noise.cpp @@ -17,7 +17,7 @@ #include #include -etk::BaseNoise::BaseNoise(ivec2 _size, float _min, float _max) : +etk::BaseNoise::BaseNoise(const ivec2& _size, float _min, float _max) : m_data(_size.x()*_size.y()), m_size(_size) { m_data.resize(_size.x()*_size.y(), 0); diff --git a/etk/Noise.h b/etk/Noise.h index 68827a4..0f8feba 100644 --- a/etk/Noise.h +++ b/etk/Noise.h @@ -16,18 +16,31 @@ namespace etk { /** * @brief BaseNoise Noise basic data. * @todo Validate it, this is a !!! PROTOTYPE !!! + * @todo Remove this from ETK */ class BaseNoise { private: - std::vector m_data; - ivec2 m_size; + std::vector m_data; //!< basic interface date + ivec2 m_size; //!< Size of the noise data public: - BaseNoise(ivec2 _size, float _min, float _max); - ~BaseNoise(); + /** + * @brief basic constructor with randon settings + * @param[in] _size Size of the basic noise + * @param[in] _min Minimum value of the random + * @param[in] _max Maximum value of the random + */ + BaseNoise(const ivec2& _size, float _min, float _max); + /** + * @brief Get value at a specific position. + * @param[in] _x X position + * @param[in] _y Y position + * @return random noise value + */ float get(int32_t _x, int32_t _y) const; }; /** * @brief List of noise type supported + * @todo Remove this from ETK */ enum noiseType { noiseType_base, //!< basic random noise @@ -41,6 +54,7 @@ namespace etk { /** * @brief Noise basic interface. * @todo Validate it, this is a !!! PROTOTYPE !!! + * @todo Remove this from ETK */ class Noise { private: diff --git a/etk/math/Matrix.h b/etk/math/Matrix.h index f6e6a10..4aac14b 100644 --- a/etk/math/Matrix.h +++ b/etk/math/Matrix.h @@ -12,75 +12,82 @@ #include namespace etk { + /** + * @brief 2 dimention matrix template to manage simpliest algo + * @note Prototype + */ template class Matrix { private: - ivec2 m_size; - std::vector m_data; + uivec2 m_size; //!< Size of the Matrix + std::vector m_data; //!< Data of the matrix public: - /***************************************************** - * Constructor - *****************************************************/ - Matrix(ivec2 _size, T* _defaultVal=nullptr) : + /** + * @brief Contructor that create a Vector with a specific size and specific raw data + * @param[in] _size Dimention of the matrix + * @param[in] _defaultVal Default list of element that might be set in the matrix + */ + Matrix(const ivec2& _size, T* _defaultVal=nullptr) : m_size(_size), - etk::Vector2D(_size.x.x()* _size.y()) { - if (defaultVal != nullptr) { - // copy all the elements - for(int32_t iii=0; iii<=m_size.x()*m_size.y(); iii++) { - // cast and set value : - m_data[iii] = T(_defaultVal++); - } - } else { - Clear(); + etk::Vector2D(_size.x()* _size.y()) { + if (defaultVal == nullptr) { + clear(); + return; } - }; + // copy all the elements + for(size_t iii = 0; + iii <= m_size.x()*m_size.y(); + ++iii) { + // cast and set value : + m_data[iii] = T(_defaultVal++); + } + } + /** + * @brief default contructor that create a Vector with a specific size and specific raw data + * @param[in] _width Dimention width of the matrix + * @param[in] _heigh Dimention heigh of the matrix + * @param[in] _defaultVal Default list of element that might be set in the matrix + */ Matrix(int32_t _width=0, int32_t _heigh=0, T* _defaultVal=nullptr) : m_size(_width, _heigh), etk::Vector2D(_width*_heigh) { - if (_defaultVal != nullptr) { - // copy all the elements - for(int32_t iii=0; iii<=m_size.x()*m_size.y(); iii++) { - // cast and set value : - m_data[iii] = (T)_defaultVal++; - } - } else { - Clear(); + if (_defaultVal == nullptr) { + clear(); + return; } - }; - Matrix(const Matrix& obj) : + // copy all the elements + for(size_t iii = 0; + iii <= m_size.x()*m_size.y(); + ++iii) { + // cast and set value : + m_data[iii] = T(_defaultVal++); + } + } + /** + * @brief Copy contructor with ETK_TYPE_MATRIX_2 type matrix input + * @param[in] _obj Object matrix to copy + */ + template + Matrix(const Matrix& _obj) : m_size(_obj.m_size), etk::Vector2D(_obj.m_size.x()* _obj.m_size.y()) { // copy all the elements - for(int32_t iii=0; iii<=m_size.x()*m_size.y(); iii++) { + for(size_t iii = 0; + iii <= m_size.x()*m_size.y(); + ++iii) { // cast and set value : - m_data[iii] = (T)_obj.m_data[iii]; + m_data[iii] = T(_obj.m_data[iii]); } } - Matrix(const Matrix& _obj) : - m_size(_obj.m_size), - etk::Vector2D(_obj.m_size.x()* _obj.m_size.y()) { - // copy all the elements - for(int32_t iii=0; iii<=m_size.x()*m_size.y(); iii++) { - // cast and set value : - m_data[iii] = (T)_obj.m_data[iii]; - } - } - Matrix(const Matrix& _obj) : - m_size(_obj.m_size.x(), _obj.m_size.y()), - etk::Vector2D(_obj.m_size.x()* _obj.m_size.y()) { - // copy all the elements - for (int32_t iii=0; iii<=m_size.x()*m_size.y(); iii++) { - // cast and set value : - m_data[iii] = (T)_obj.m_data[iii]; - } - } - /***************************************************** - * Destructor - *****************************************************/ - virtual ~Matrix() {}; + /** + * @brief Virtualisation of destructor + */ + virtual ~Matrix() = default; - /***************************************************** - * = assigment - *****************************************************/ + /** + * @brief Operator= Asign the current object with an other object + * @param[in] _obj Reference on the external object + * @return Local reference of the vector asigned + */ const Matrix& operator= (const Matrix& _obj ) { // check if it was the same pointer if (this == &_obj ) { @@ -90,29 +97,49 @@ namespace etk { m_size = _obj.m_size; m_data = _obj.m_data; return *this; - }; + } + /** + * @brief Operator= Asign the current object with a unique value + * @param[in] _value Value to set in the matrix data + * @return Local reference of the vector asigned + */ const Matrix& operator= (T& _value) { // set data : - for (int32_t iii=0; iii& _obj) const { return (m_data == _obj.m_data); - }; - /***************************************************** - * != operator - *****************************************************/ + } + /** + * @brief In-Equality compare operator with an other object. + * @param[in] _obj Reference on the comparing object + * @return true The Objects are NOT identical + * @return false The Objects are identical + */ bool operator!= (const Matrix& _obj) const { return (m_data != _obj.m_data); - }; - /***************************************************** - * += operator - *****************************************************/ + } + /** + * @brief Operator+= Addition an other matrix with this one + *
+			 *    (a b)   (e f)   (a+e b+f)
+			 *    (c d) + (g h) = (c+g d+h)
+			 * 
+ * @note If the size are different, we create a matrix witth the max size of the 2 others ... + * @param[in] _obj Reference on the external object + * @return Local reference of the vector additionned + */ const Matrix& operator+= (const Matrix& _obj) { if (m_size != _obj.m_size) { //TK_CRITICAL("add 2 Matrix with différent size ... ==> generate the max size of all the 2 matrix"); @@ -135,27 +162,41 @@ namespace etk { m_size = tmpMatrix.m_size; m_data = tmpMatrix.m_data; } else { - // copy data for the same size : + // copy data for the same size: for (int32_t iii=0; iii< m_data.size(); iii++) { m_data[iii] += _obj.m_data[iii]; } } return *this; - }; - /***************************************************** - * + operator - *****************************************************/ + } + /** + * @brief Operator+= Addition an other matrix with this one + *
+			 *    (a b)   (e f)   (a+e b+f)
+			 *    (c d) + (g h) = (c+g d+h)
+			 * 
+ * @note If the size are different, we create a matrix witth the max size of the 2 others ... + * @param[in] _obj Reference on the external object + * @return New matrix containing the value + */ Matrix operator+ (const Matrix& _obj) { Matrix tmpp(*this); tmpp += _obj; return tmpp; } - /***************************************************** - * -= operator - *****************************************************/ + /** + * @brief Operator+= Addition an other matrix with this one + *
+			 *    (a b)   (e f)   (a-e b-f)
+			 *    (c d) - (g h) = (c-g d-h)
+			 * 
+ * @note If the size are different, we create a matrix witth the max size of the 2 others ... + * @param[in] _obj Reference on the external object + * @return Local reference of the vector additionned + */ const Matrix& operator-= (const Matrix& _obj) { if (m_size != _obj.m_size) { - //TK_CRITICAL("less 2 Matrix with différent size ... ==> generate the max size of all the 2 matrix"); + //TK_CRITICAL("less 2 Matrix with different size ... ==> generate the max size of all the 2 matrix"); etk::Matrix tmpMatrix(std::max(m_size.x(),_obj.m_size.x()), std::max(m_size.y(),_obj.m_size.y())); for (int32_t jjj=0; jjj< m_size.y; jjj++) { T* tmpPointer = tmpMatrix[jjj]; @@ -182,17 +223,26 @@ namespace etk { } return *this; }; - /***************************************************** - * - operator - *****************************************************/ + /** + * @brief Operator+= Addition an other matrix with this one + *
+			 *    (a b)   (e f)   (a-e b-f)
+			 *    (c d) - (g h) = (c-g d-h)
+			 * 
+ * @note If the size are different, we create a matrix witth the max size of the 2 others ... + * @param[in] _obj Reference on the external object + * @return New matrix containing the value + */ Matrix operator- (const Matrix& _obj) { Matrix tmpp(*this); tmpp += _obj; return tmpp; } - /***************************************************** - * *= operator - *****************************************************/ + /** + * @brief Operator*= Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector multiplicated + */ const Matrix& operator*= (const Matrix& _obj) { if( m_size.x() != _obj.m_size.y() || m_size.y() != _obj.m_size.x()) { @@ -213,46 +263,89 @@ namespace etk { m_data = tmpMatrix.m_data; return *this; }; - /***************************************************** - * * operator - *****************************************************/ + /** + * @brief Operator* Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New matrix containing the value + */ Matrix operator* (const Matrix& _obj) { Matrix tmpp(*this); tmpp *= _obj; return tmpp; } - /***************************************************** - * [] operator - *****************************************************/ - const T* operator[] (int32_t _line) const { - return &m_data[_line*m_size.x()]; + // TODO : Check if is possible to do elemntValue = mayMatrix[xxx, yyy] + /** + * @brief Operator[] Access at the first element (const pointer) of a line + *
+			 *   elemntValue = mayMatrix[YYY][xxx];
+			 * 
+ * @param[in] _yyy Line Id requested [0..m_size.y()] + * @return Const pointer on the first line element + */ + const T* operator[] (int32_t _yyy) const { + return &m_data[_yyy*m_size.x()]; } - T* operator[] (int32_t _line) { - return &m_data[_line*m_size.x()]; + /** + * @brief Operator[] Access at the first element (pointer) of a line + *
+			 *   elemntValue = mayMatrix[YYY][xxx];
+			 * 
+ * @param[in] _yyy Line Id requested [0..m_size.y()] + * @return Pointer on the first line element + */ + T* operator[] (int32_t _yyy) { + return &m_data[_yyy*m_size.x()]; } - /***************************************************** - * () operator - *****************************************************/ - T& operator () (int32_t _line, int32_t _colomn) { - return m_data[_line*m_size.x() + _colomn]; + /** + * @brief Operator[] Access at the element at a specific position + *
+			 *   elemntValue = mayMatrix[ivec2(xxx,yyy)];
+			 * 
+ * @param[in] _pos Position in the matrix + * @return Const Reference on the element + */ + const T& operator[] (const ivec2& _pos) const { + return m_data[_pos.y()*m_size.x() + _pos.x()]; } - /***************************************************** - * - operator - *****************************************************/ - Matrix operator - () { + /** + * @brief Operator[] Access at the element at a specific position + *
+			 *   elemntValue = mayMatrix[ivec2(xxx,yyy)];
+			 * 
+ * @param[in] _pos Position in the matrix + * @return Reference on the element + */ + T& operator[] (const ivec2& _pos) { + return m_data[_pos.y()*m_size.x() + _pos.x()]; + } + /** + * @brief Operator() Access at the element at a specific position + *
+			 *   elemntValue = mayMatrix(xxx,yyy);
+			 * 
+ * @param[in] _xxx Colomn position in the matrix + * @param[in] _yyy Line position in the matrix + * @return Reference on the element + */ + T& operator () (size_t _xxx, size_t _yyy) { + return m_data[_yyy*m_size.x() + _xxx]; + } + /** + * @brief Operator- Multiply with -1 + * @return New matrix containing the value + */ + Matrix operator- () const { Matrix tmp(m_size); for (int32_t iii=0; iii transpose() { + Matrix transpose() const { // create a matrix with the inverted size Matrix tmpMatrix(m_size); for (int32_t jjj=0; jjj< m_size.y(); jjj++) { @@ -261,23 +354,23 @@ namespace etk { } } return tmpMatrix; - }; + } /** - * @ brief Create a convolution on the matrix : set convolution on the lines - * @ param[in] _obj The convolution operator - * @ return the value of the convolution + * @brief Create a convolution on the matrix : set convolution on the lines + * @param[in] _obj The convolution operator + * @return New matrix containing the current matrix concoluate */ - Matrix& convolution(Matrix& _obj) { + Matrix convolution(Matrix& _obj) const { Matrix tmppp(1,1); // TODO : ... return tmppp; - }; + } /** - * @ brief generate a devide of the curent Matrix with the specify power of 2 - * @ param[in] _decalage The power of 2 of the division - * @ return the result + * @brief generate a devide of the curent Matrix with the specify power of 2 + * @param[in] _decalage The power of 2 of the division + * @return New matrix containing the matrix fix() */ - Matrix& fix(int32_t _decalage) { + Matrix fix(int32_t _decalage) const { Matrix tmppp(m_size); T tmpVal = 0; for(int32_t iii=0; iii& round(int32_t _decalage) { + Matrix round(int32_t _decalage) const { Matrix tmppp(m_size); for(int32_t iii=0; iii> _decalage; @@ -305,11 +398,11 @@ namespace etk { return tmppp; }; /** - * @ brief Generate a resised matrix - * @ param[in] _size new output size - * @ return Te resied matrix + * @brief Generate a resised matrix + * @param[in] _size new output size + * @return New matrix resized */ - Matrix& resize(etk::Vector2D _size) { + Matrix resize(etk::Vector2D _size) const { Matrix tmppp(_size); for(int32_t iii=0; iii& select(int32_t _np, int32_t* _p, int32_t _nq, int32_t* _q) { + Matrix select(int32_t _np, int32_t* _p, int32_t _nq, int32_t* _q) const { if (_np < 1 || _nq < 1) { TK_WARNING("bad index array sizes"); } @@ -344,9 +437,6 @@ namespace etk { } return tmppp; } - /***************************************************** - * utilities : - *****************************************************/ /** * @brief Clear the Upper triangle of the current Matrix *
@@ -401,7 +491,7 @@ namespace etk {
 			 * @param[in] _input The compared Matix.
 			 * @return The absolute max value.
 			 */
-			T maxDifference(const Matrix& _input) {
+			T maxDifference(const Matrix& _input) const {
 				if (m_size != _input.m_size) {
 					TK_WARNING("better to do with same size Matrix");
 				}
@@ -413,14 +503,21 @@ namespace etk {
 					if (diff<0) {
 						diff = -diff;
 					}
-					if (diff > max)
+					if (diff > max) {
 						max = diff;
 					}
 				}
 				return max;
-			};
+			}
 			/**
 			 * @brief Clear all the matrix.
+			 * 
+			 *   0 0 0 0 0
+			 *   0 0 0 0 0
+			 *   0 0 0 0 0
+			 *   0 0 0 0 0
+			 *   0 0 0 0 0
+			 * 
*/ void clear() { // copy data for the same size : @@ -429,7 +526,13 @@ namespace etk { } }; /** - * @brief Set the diagonal at 1 + * @brief Set the matrix identity + *
+			 *   1 0 0 0 0
+			 *   0 1 0 0 0
+			 *   0 0 1 0 0
+			 *   0 0 0 1 0
+			 * 
*/ void identity() { // copy data for the same size : @@ -448,13 +551,14 @@ namespace etk { * @brief Get the size of the current Matrix. * @return Dimention of the matrix */ - Vector2D size() { + const uivec2& size() const { return m_size; }; }; } // To siplify the writing of the code ==> this is not compatible with GLSL ... -typedef etk::Matrix mat; -typedef etk::Matrix imat; -typedef etk::Matrix uimat; +using dmat = etk::Matrix; //!< Helper to simplify using of matrix +using mat = etk::Matrix; //!< Helper to simplify using of matrix +using imat = etk::Matrix; //!< Helper to simplify using of matrix +using uimat = etk::Matrix; //!< Helper to simplify using of matrix diff --git a/etk/math/Matrix2.cpp b/etk/math/Matrix2.cpp index c2c5976..e54a1f8 100644 --- a/etk/math/Matrix2.cpp +++ b/etk/math/Matrix2.cpp @@ -78,10 +78,6 @@ etk::Matrix2::Matrix2(const double* _values) { m_mat[5] = _values[5]; } -etk::Matrix2::~Matrix2() { - -} - const etk::Matrix2& etk::Matrix2::operator= (const etk::Matrix2& _obj ) { for(int32_t iii=0; iii<2*3 ; ++iii) { m_mat[iii] = _obj.m_mat[iii]; @@ -152,14 +148,14 @@ etk::Matrix2 etk::Matrix2::operator * (const etk::Matrix2& _obj) { return tmp; } -vec2 etk::Matrix2::operator * (const vec2& _obj) const { - return vec2(_obj.x()*m_mat[0] + _obj.y()*m_mat[1] + m_mat[2], - _obj.x()*m_mat[4] + _obj.y()*m_mat[3] + m_mat[5]); +vec2 etk::Matrix2::operator * (const vec2& _point) const { + return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1] + m_mat[2], + _point.x()*m_mat[4] + _point.y()*m_mat[3] + m_mat[5]); } -vec2 etk::Matrix2::applyScaleRotation(const vec2& _obj) const { - return vec2(_obj.x()*m_mat[0] + _obj.y()*m_mat[1], - _obj.x()*m_mat[4] + _obj.y()*m_mat[3]); +vec2 etk::Matrix2::applyScaleRotation(const vec2& _point) const { + return vec2(_point.x()*m_mat[0] + _point.y()*m_mat[1], + _point.x()*m_mat[4] + _point.y()*m_mat[3]); } etk::Matrix2 etk::Matrix2::operator ~ () const { diff --git a/etk/math/Matrix2.h b/etk/math/Matrix2.h index 61cbd68..8d7e4d3 100644 --- a/etk/math/Matrix2.h +++ b/etk/math/Matrix2.h @@ -11,76 +11,128 @@ #include #include namespace etk { + /** + * @brief Transformation matrix for vector 2D. + */ class Matrix2 { - public: - /* + private: + /** + * @brief Internal data * sx shx tx * sy shy ty */ float m_mat[2*3]; - /** - * @brief Load Identity matrix - */ - void identity(); public: - /***************************************************** - * Constructor - *****************************************************/ + /** + * @brief Constructor that load identity + */ Matrix2(); + /** + * @brief Copy constructor. + * @param[in] _obj Matrix object to copy + */ Matrix2(const Matrix2& _obj); + /** + * @brief Configuration constructor. + * @param[in] _sx Scale threw X axis + * @param[in] _shy Rotate in radian threw Y axis + * @param[in] _shx Rotate in radian threw X axis + * @param[in] _sy Scale threw Y axis + * @param[in] _tx Translate threw X axis + * @param[in] _ty translate threw Y axis + */ Matrix2(float _sx, float _shy, float _shx, float _sy, float _tx, float _ty); + /** + * @brief Configuration constructor. + * @param[in] _values vector of values in float + */ Matrix2(const float* _values); + /** + * @brief Configuration constructor. + * @param[in] _values vector of values in double + */ Matrix2(const double* _values); - /***************************************************** - * Destructor - *****************************************************/ - ~Matrix2(); - /***************************************************** - * = assigment - *****************************************************/ + /** + * @brief Load Identity matrix + */ + void identity(); + /** + * @brief Operator= Asign the current object with an other object + * @param[in] _obj Reference on the external object + * @return Local reference of the vector asigned + */ const Matrix2& operator= (const Matrix2& _obj ); - /***************************************************** - * == operator - *****************************************************/ + /** + * @brief Equality compare operator with an other object. + * @param[in] _obj Reference on the comparing object + * @return true The Objects are identical + * @return false The Objects are NOT identical + */ bool operator== (const Matrix2& _obj) const; - /***************************************************** - * != operator - *****************************************************/ + /** + * @brief In-Equality compare operator with an other object. + * @param[in] _obj Reference on the comparing object + * @return true The Objects are NOT identical + * @return false The Objects are identical + */ bool operator!= (const Matrix2& _obj) const; - /***************************************************** - * += operator - *****************************************************/ + /** + * @brief Operator+= Addition an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector additionned + */ const Matrix2& operator+= (const Matrix2& _obj); - /***************************************************** - * + operator - *****************************************************/ + /** + * @brief Operator+ Addition an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix2 operator+ (const Matrix2& _obj) const; - /***************************************************** - * -= operator - *****************************************************/ + /** + * @brief Operator-= Decrement an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector decremented + */ const Matrix2& operator-= (const Matrix2& _obj); - /***************************************************** - * - operator - *****************************************************/ + /** + * @brief Operator- Decrement an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix2 operator- (const Matrix2& _obj) const; - /***************************************************** - * *= operator - *****************************************************/ + /** + * @brief Operator*= Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector multiplicated + */ const Matrix2& operator *= (const Matrix2& _obj); - /***************************************************** - * * operator - *****************************************************/ + /** + * @brief Operator* Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix2 operator * (const Matrix2& _obj); - vec2 operator * (const vec2& _obj) const; - vec2 applyScaleRotation(const vec2& _obj) const; - /***************************************************** - * ~ operator - *****************************************************/ + /** + * @brief Operator* apply matrix on a vector + * @param[in] _point Point value to apply the matrix + * @return New vector containing the value + */ + vec2 operator * (const vec2& _point) const; + /** + * @brief Apply matrix on a vector Scale Rotate, but NOT the translation + * @param[in] _point Point value to apply the matrix + * @return New vector containing the value + */ + vec2 applyScaleRotation(const vec2& _point) const; + /** + * @brief Inverse the current Matrix + * @return New vector containing the value + */ Matrix2 operator ~ () const; /** * @brief Flip the mathix threw the X axis @@ -93,10 +145,12 @@ namespace etk { /** * @brief Scale the current Matrix. * @param[in] _vect Vector to scale matrix. - * @param[in] _value Single value to scale in X andf Y. */ void scale(const vec2& _vect); - //! @previous + /** + * @brief Scale the current Matrix. + * @param[in] _value Single value to scale in X andf Y. + */ void scale(float _value); /** * @brief Makes a rotation matrix. @@ -120,15 +174,40 @@ namespace etk { */ void invert(); }; + /** + * @brief Create a matrix 2D with a simple rotation + * @param[in] _angleRad Radian angle to set at the matrix + * @return New matrix of the transformation requested + */ Matrix2 mat2Rotate(float _angleRad); + /** + * @brief Create a matrix 2D with a simple scale + * @param[in] _scale 2 dimention scale + * @return New matrix of the transformation requested + */ Matrix2 mat2Scale(const vec2& _scale); + /** + * @brief Create a matrix 2D with a simple scale + * @param[in] _scale same scale in 2 and Y + * @return New matrix of the transformation requested + */ Matrix2 mat2Scale(float _scale); + /** + * @brief Create a matrix 2D with a simple translation + * @param[in] _translate 2 dimention translation + * @return New matrix of the transformation requested + */ Matrix2 mat2Translate(const vec2& _translate); + /** + * @brief Create a matrix 2D with a simple skew + * @param[in] _skew 2 dimention skew + * @return New matrix of the transformation requested + */ Matrix2 mat2Skew(const vec2& _skew); //! @not_in_doc std::ostream& operator <<(std::ostream& _os, const etk::Matrix2& _obj); } // simplify using of matrix ... -typedef etk::Matrix2 mat2; +using mat2 = etk::Matrix2; //!< Use simplification in upper application to use matrix like openGL shader diff --git a/etk/math/Matrix4.cpp b/etk/math/Matrix4.cpp index f8f542a..efb1997 100644 --- a/etk/math/Matrix4.cpp +++ b/etk/math/Matrix4.cpp @@ -11,8 +11,6 @@ #include #include -#if 1 - void etk::Matrix4::identity() { for(int32_t iii=0; iii<4*4 ; iii++) { m_mat[iii] = 0; @@ -65,10 +63,6 @@ etk::Matrix4::Matrix4(float* _obj) { } } -etk::Matrix4::~Matrix4() { - -} - const etk::Matrix4& etk::Matrix4::operator= (const etk::Matrix4& _obj ) { for(int32_t iii=0; iii<4*4 ; ++iii) { m_mat[iii] = _obj.m_mat[iii]; @@ -442,5 +436,3 @@ mat4 etk::matRotate(const vec3& _vect, float _angleRad) { return tmp; } -#endif - diff --git a/etk/math/Matrix4.h b/etk/math/Matrix4.h index 122ea07..8a377ac 100644 --- a/etk/math/Matrix4.h +++ b/etk/math/Matrix4.h @@ -12,78 +12,147 @@ #include -#if 1 #include +/** + * @brief Convert degree in radian + * @param[in] a Value to converted in degree + * @return Angle in radian + */ #define DEG_TO_RAD(a) ((a)*M_PI/180.0f) +/** + * @brief Convert radian in degree + * @param[in] a Value to converted in radian + * @return Angle in degree + */ #define RAD_TO_DEG(a) ((a)*180.0f/M_PI) namespace etk { + /** + * @brief Transformation matrix for vector 3D. + */ class Matrix4 { + private: + float m_mat[4*4]; //!< matrix data public: - float m_mat[4*4]; + /** + * @brief configure identity of the matrix + */ void identity(); - /***************************************************** - * Constructor - *****************************************************/ + /** + * @brief Constructor that load identity + */ Matrix4(); + /** + * @brief Copy constructor. + * @param[in] _obj Matrix object to copy + */ Matrix4(const Matrix4& _obj); + /** + * @brief Configuration constructor. + * @param[in] _a1 1st colomn, 1 line value + * @param[in] _b1 2nd colomn, 1 line value + * @param[in] _c1 3rd colomn, 1 line value + * @param[in] _d1 4th colomn, 1 line value + * @param[in] _a2 1st colomn, 2 line value + * @param[in] _b2 2nd colomn, 2 line value + * @param[in] _c2 3rd colomn, 2 line value + * @param[in] _d2 4th colomn, 2 line value + * @param[in] _a3 1st colomn, 3 line value + * @param[in] _b3 2nd colomn, 3 line value + * @param[in] _c3 3rd colomn, 3 line value + * @param[in] _d3 4th colomn, 3 line value + * @param[in] _a4 1st colomn, 4 line value + * @param[in] _b4 2nd colomn, 4 line value + * @param[in] _c4 3rd colomn, 4 line value + * @param[in] _d4 4th colomn, 4 line value + */ Matrix4(float _a1, float _b1, float _c1, float _d1, float _a2, float _b2, float _c2, float _d2, float _a3, float _b3, float _c3, float _d3, float _a4, float _b4, float _c4, float _d4); - Matrix4(float* _obj); - /***************************************************** - * Destructor - *****************************************************/ - ~Matrix4(); - /***************************************************** - * = assigment - *****************************************************/ - const Matrix4& operator= (const Matrix4& _obj ); - /***************************************************** - * == operator - *****************************************************/ + /** + * @brief Configuration constructor. + * @param[in] _values vector of values + */ + Matrix4(float* _values); + /** + * @brief Operator= Asign the current object with an other object + * @param[in] _obj Reference on the external object + * @return Local reference of the vector asigned + */ + const Matrix4& operator= (const Matrix4& _obj); + /** + * @brief Equality compare operator with an other object. + * @param[in] _obj Reference on the comparing object + * @return true The Objects are identical + * @return false The Objects are NOT identical + */ bool operator== (const Matrix4& _obj) const; - /***************************************************** - * != operator - *****************************************************/ + /** + * @brief In-Equality compare operator with an other object. + * @param[in] _obj Reference on the comparing object + * @return true The Objects are NOT identical + * @return false The Objects are identical + */ bool operator!= (const Matrix4& _obj) const; - /***************************************************** - * += operator - *****************************************************/ + /** + * @brief Operator+= Addition an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector additionned + */ const Matrix4& operator+= (const Matrix4& _obj); - /***************************************************** - * + operator - *****************************************************/ + /** + * @brief Operator+ Addition an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix4 operator+ (const Matrix4& _obj) const; - /***************************************************** - * -= operator - *****************************************************/ + /** + * @brief Operator-= Decrement an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector decremented + */ const Matrix4& operator-= (const Matrix4& _obj); - /***************************************************** - * - operator - *****************************************************/ + /** + * @brief Operator- Decrement an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix4 operator- (const Matrix4& _obj) const; - /***************************************************** - * *= operator - *****************************************************/ + /** + * @brief Operator*= Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return Local reference of the vector multiplicated + */ const Matrix4& operator*= (const Matrix4& _obj); - /***************************************************** - * * operator - *****************************************************/ + /** + * @brief Operator* Multiplication an other matrix with this one + * @param[in] _obj Reference on the external object + * @return New vector containing the value + */ Matrix4 operator* (const Matrix4& _obj) const; + /** + * @brief Operator* apply matrix on a vector + * @param[in] _point Point value to apply the matrix + * @return New vector containing the value + */ vec3 operator*(const vec3& _point) const; - /***************************************************** - * other basic function : - *****************************************************/ + /** + * @brief Transpose the current matix (usefull for OpenGL display) + */ void transpose(); /** * @brief Scale the current Matrix. * @param[in] _vect Scale vector to apply. */ void scale(const vec3& _vect); - //! @previous + /** + * @brief Scale the current Matrix. + * @param[in] _sx Scale X value to apply. + * @param[in] _sy Scale Y value to apply. + * @param[in] _sz Scale Z value to apply. + */ void scale(float _sx, float _sy, float _sz); /** * @brief Makes a rotation matrix about an arbitrary axis. @@ -118,9 +187,26 @@ namespace etk { Matrix4 matFrustum(float _xmin, float _xmax, float _ymin, float _ymax, float _zNear, float _zFar); Matrix4 matPerspective(float _foxy, float _aspect, float _zNear, float _zFar); Matrix4 matOrtho(float _left, float _right, float _bottom, float _top, float _nearVal, float _farVal); - Matrix4 matTranslate(vec3 _vect); - Matrix4 matScale(vec3 _vect); - Matrix4 matRotate(vec3 _vect, float _angleRad=0.0); + /** + * @brief Create a matrix 3D with a simple translation + * @param[in] _translate 3 dimention translation + * @return New matrix of the transformation requested + */ + Matrix4 matTranslate(vec3 _translate); + /** + * @brief Create a matrix 3D with a simple scale + * @param[in] _scale 3 dimention scale + * @return New matrix of the transformation requested + */ + Matrix4 matScale(vec3 _scale); + /** + * @brief Create a matrix 3D with a simple rotation + * @param[in] _normal vector aroud witch apply the rotation + * @param[in] _angleRad Radian angle to set at the matrix + * @return New matrix of the transformation requested + */ + Matrix4 matRotate(vec3 _normal, float _angleRad=0.0); + //! @not_in_doc Matrix4 matRotate2(vec3 _vect); Matrix4 matLookAt(const vec3& _eye, const vec3& _target, @@ -131,21 +217,5 @@ namespace etk { // To siplify the writing of the code ==> this permit to have the same name with the glsl language... -typedef etk::Matrix4 mat4; -#else - // include matrix from bulletlib mat4 interface: - #include - // To siplify the writing of the code ==> this permit to have the same name with the glsl language... - typedef Vectormath::Aos::Matrix4 mat4; - //! @not_in_doc - std::ostream& operator <<(std::ostream& _os, const mat4& _obj); - - // TODO : Remove this ??? - namespace etk { - mat4 matTranslate(const vec3& _vect); - mat4 matScale(const vec3& _vect); - mat4 matRotate(const vec3& _vect, float _angleRad=0.0); - } -#endif - +using mat4 = etk::Matrix4; //!< Matrix naming like openGl shader diff --git a/etk/math/Vector2D.h b/etk/math/Vector2D.h index 47bfefe..7fb451a 100644 --- a/etk/math/Vector2D.h +++ b/etk/math/Vector2D.h @@ -98,7 +98,7 @@ namespace etk { * @return true The Objects are identical * @return false The Objects are NOT identical */ - bool operator== (const Vector2D& _obj) const { + bool operator== (const Vector2D& _obj) const { return ( (T)_obj.m_floats[0] == m_floats[0] && (T)_obj.m_floats[1] == m_floats[1]); } @@ -108,7 +108,7 @@ namespace etk { * @return true The Objects are NOT identical * @return false The Objects are identical */ - bool operator!= (const Vector2D& _obj) const { + bool operator!= (const Vector2D& _obj) const { return ( (T)_obj.m_floats[0] != m_floats[0] || (T)_obj.m_floats[1] != m_floats[1]); } diff --git a/etk/math/Vector3D.h b/etk/math/Vector3D.h index 8a4033f..58c1313 100644 --- a/etk/math/Vector3D.h +++ b/etk/math/Vector3D.h @@ -532,15 +532,15 @@ namespace etk { // To siplify the writing of the code ==> this permit to have the same name with the glsl language... #ifdef ETK_BUILD_LINEARMATH - typedef btVector3 vec3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader + using vec3 = btVector3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader #else - typedef etk::Vector3D vec3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader + using vec3 = etk::Vector3D; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader #endif -typedef etk::Vector3D ovec3; //!< wrapper on etk::Vector3D to be complient all time with openGL internal mode (instead of vec3) -typedef etk::Vector3D ivec3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader +using ovec3 = etk::Vector3D; //!< wrapper on etk::Vector3D to be complient all time with openGL internal mode (instead of vec3) +using ivec3 = etk::Vector3D; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader // not compatible with glsl ... but it is better to have a same writing -typedef etk::Vector3D uivec3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader -typedef etk::Vector3D bvec3; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader +using uivec3 = etk::Vector3D; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader +using bvec3 = etk::Vector3D; //!< wrapper on etk::Vector3D to have the same naming has OpenGL shader //! @not_in_doc std::ostream& operator <<(std::ostream& _os, const vec3& _obj); diff --git a/etk/math/Vector4D.h b/etk/math/Vector4D.h index 37dc05e..d3ddd7b 100644 --- a/etk/math/Vector4D.h +++ b/etk/math/Vector4D.h @@ -432,10 +432,10 @@ namespace etk { } // To siplify the writing of the code ==> this permit to have the same name with the glsl language... -typedef etk::Vector4D vec4; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader -typedef etk::Vector4D ivec4; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader +using vec4 = etk::Vector4D; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader +using ivec4 = etk::Vector4D; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader // not compatible with glsl ... but it is better to have a same writing -typedef etk::Vector4D uivec4; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader -typedef etk::Vector4D bvec4; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader +using uivec4 = etk::Vector4D; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader +using bvec4 = etk::Vector4D; //!< wrapper on etk::Vector4D to have the same naming has OpenGL shader diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index bab352c..61f8db1 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -228,14 +228,14 @@ void etk::setArgZero(const std::string& _val) { Afterwards it may be reasonable to check whether the executable isn't actually a symlink. If it is resolve it relative to the symlink directory. This step is not necessary in /proc method (at least for Linux). There the proc symlink points directly to executable. Note that it is up to the calling process to set argv[0] correctly. It is right most of the times however there are occasions when the calling process cannot be trusted (ex. setuid executable). - On Windows: use GetModuleFileName(NULL, buf, bufsize) + On Windows: use GetModuleFileName(nullptr, buf, bufsize) */ std::string getApplicationPath() { std::string binaryName = "no-name"; char binaryCompleatePath[FILENAME_MAX]; memset(binaryCompleatePath, 0, FILENAME_MAX); #ifdef __TARGET_OS__Windows - GetModuleFileName(NULL, binaryCompleatePath, FILENAME_MAX); + GetModuleFileName(nullptr, binaryCompleatePath, FILENAME_MAX); if (0==strlen(binaryCompleatePath)) { TK_CRITICAL("Can not get the binary position in the tree ==> this is really bad ..."); } else { @@ -278,7 +278,7 @@ std::string getApplicationPath() { } TK_VERBOSE("Parse arg0 = '" << l_argZero << "' try add PWD"); char * basicPathPWD = getenv("PWD"); - if (NULL != basicPathPWD) { + if (nullptr != basicPathPWD) { std::string testCompleatePath = basicPathPWD; testCompleatePath += "/"; testCompleatePath += l_argZero; @@ -294,7 +294,7 @@ std::string getApplicationPath() { } } //char * basicPathPATH = getenv("PATH"); - //if (NULL != basicPathPWD) { + //if (nullptr != basicPathPWD) { // TODO : bad case ... //} // and now we will really in a bad mood ... @@ -312,7 +312,7 @@ void etk::initDefaultFolder(const char* _applName) { baseApplName = _applName; char cCurrentPath[FILENAME_MAX]; char * basicPath = getenv("HOME"); - if (NULL == basicPath) { + if (nullptr == basicPath) { TK_WARNING("ERROR while trying to get the path of the home folder"); #if defined(__TARGET_OS__Windows) baseFolderHome = "c:/"; @@ -498,7 +498,7 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) { char *sp; int status; char *copypath = strdup(_path); - if (NULL==copypath) { + if (nullptr==copypath) { return -1; } status = 0; @@ -521,14 +521,14 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) { etk::FSNode::FSNode(const std::string& _nodeName) : m_userFileName(""), - m_type(etk::FSN_TYPE_UNKNOW), - m_typeNode(etk::FSN_UNKNOW), - m_PointerFile(NULL), + m_type(etk::FSNType_unknow), + m_typeNode(etk::typeNode_unknow), + m_PointerFile(nullptr), m_timeCreate(0), m_timeModify(0), m_timeAccess(0) #ifdef HAVE_ZIP_DATA - , m_zipContent(NULL), + , m_zipContent(nullptr), m_zipReadingOffset(-1) #endif { @@ -537,14 +537,14 @@ etk::FSNode::FSNode(const std::string& _nodeName) : #if __CPP_VERSION__ >= 2011 etk::FSNode::FSNode(const std::u32string& _nodeName) : m_userFileName(""), - m_type(etk::FSN_TYPE_UNKNOW), - m_typeNode(etk::FSN_UNKNOW), - m_PointerFile(NULL), + m_type(etk::FSNType_unknow), + m_typeNode(etk::typeNode_unknow), + m_PointerFile(nullptr), m_timeCreate(0), m_timeModify(0), m_timeAccess(0) #ifdef HAVE_ZIP_DATA - , m_zipContent(NULL), + , m_zipContent(nullptr), m_zipReadingOffset(-1) #endif { @@ -554,9 +554,9 @@ etk::FSNode::FSNode(const std::string& _nodeName) : etk::FSNode::~FSNode() { - if( NULL != m_PointerFile + if( nullptr != m_PointerFile #ifdef HAVE_ZIP_DATA - || NULL != m_zipContent + || nullptr != m_zipContent #endif ) { TK_ERROR("Missing to close the file : \"" << *this << "\""); @@ -569,11 +569,11 @@ void etk::FSNode::sortElementList(std::vector& _list) { std::vector tmpList = _list; _list.clear(); for(size_t iii=0; iiigetNameFile()) > etk::toupper(_list[jjj]->getNameFile())) { findPos = jjj+1; @@ -587,15 +587,15 @@ void etk::FSNode::sortElementList(std::vector& _list) { } void etk::FSNode::privateSetName(std::string _newName) { - if( NULL != m_PointerFile + if( nullptr != m_PointerFile #ifdef HAVE_ZIP_DATA - || NULL != m_zipContent + || nullptr != m_zipContent #endif ) { TK_ERROR("Missing to close the file : \"" << *this << "\""); fileClose(); } - // set right at NULL ... + // set right at nullptr ... m_rights = 0; m_libSearch = ""; @@ -615,12 +615,12 @@ void etk::FSNode::privateSetName(std::string _newName) { } #ifdef HAVE_ZIP_DATA - m_zipContent = NULL; + m_zipContent = nullptr; m_zipReadingOffset = 0; #endif // Reset ALL DATA : m_userFileName = ""; - m_type = etk::FSN_TYPE_UNKNOW; + m_type = etk::FSNType_unknow; TK_DBG_MODE("1 : Set Name : \"" << _newName << "\""); // generate destination name in case of the input error @@ -652,47 +652,47 @@ void etk::FSNode::privateSetName(std::string _newName) { || start_with(destFilename, "root:") == true ) { TK_DBG_MODE(" ==> detect root 2 "); destFilename.erase(0, 5); - m_type = etk::FSN_TYPE_DIRECT; + m_type = etk::FSNType_direct; if(start_with(destFilename, "~") == true) { destFilename.erase(0, 1); - m_type = etk::FSN_TYPE_HOME; + m_type = etk::FSNType_home; } } else if( start_with(destFilename, "DIRECT:") == true || start_with(destFilename, "direct:") == true ) { TK_DBG_MODE(" ==> detect direct"); destFilename.erase(0, 7); - m_type = etk::FSN_TYPE_DIRECT; + m_type = etk::FSNType_direct; if(start_with(destFilename, "~") == true) { destFilename.erase(0, 1); - m_type = etk::FSN_TYPE_HOME; + m_type = etk::FSNType_home; } } else if( start_with(destFilename, "DATA:") == true || start_with(destFilename, "data:") == true ) { TK_DBG_MODE(" ==> detect data"); destFilename.erase(0, 5); - m_type = etk::FSN_TYPE_DATA; + m_type = etk::FSNType_data; } else if( start_with(destFilename, "USERDATA:") == true || start_with(destFilename, "userdata:") == true ) { TK_DBG_MODE(" ==> detect User-data"); destFilename.erase(0, 9); - m_type = etk::FSN_TYPE_USER_DATA; + m_type = etk::FSNType_userData; } else if( start_with(destFilename, "CACHE:") == true || start_with(destFilename, "cache:") == true ) { TK_DBG_MODE(" ==> detect Cache"); destFilename.erase(0, 6); - m_type = etk::FSN_TYPE_CACHE; + m_type = etk::FSNType_cache; } else if( start_with(destFilename, "THEME:") == true || start_with(destFilename, "theme:") == true ) { TK_DBG_MODE(" ==> detect theme"); destFilename.erase(0, 6); - m_type = etk::FSN_TYPE_THEME; + m_type = etk::FSNType_theme; } else if(start_with(destFilename, "./") == true) { TK_DBG_MODE(" ==> detect relatif 1"); destFilename.erase(0, 2); while (destFilename.size()>0 && destFilename[0] == '/') { destFilename.erase(0, 1); } - m_type = etk::FSN_TYPE_RELATIF; + m_type = etk::FSNType_relatif; } else if( start_with(destFilename, "REL:") == true || start_with(destFilename, "rel:") == true ) { TK_DBG_MODE(" ==> detect relatif 2"); @@ -700,14 +700,14 @@ void etk::FSNode::privateSetName(std::string _newName) { while (destFilename.size()>0 && destFilename[0] == '/') { destFilename.erase(0, 1); } - m_type = etk::FSN_TYPE_RELATIF; + m_type = etk::FSNType_relatif; } else if(start_with(destFilename, baseRunPath) == true) { TK_DBG_MODE(" ==> detect relatif 3 (run path=" << baseRunPath << ")"); destFilename.erase(0, baseRunPath.size()); while (destFilename.size()>0 && destFilename[0] == '/') { destFilename.erase(0, 1); } - m_type = etk::FSN_TYPE_RELATIF; + m_type = etk::FSNType_relatif; } else if (( baseRunPath != baseRunPathInHome && ( start_with(destFilename, "~" + baseRunPathInHome) == true || start_with(destFilename, "HOME:" + baseRunPathInHome) == true @@ -722,23 +722,23 @@ void etk::FSNode::privateSetName(std::string _newName) { while (destFilename.size()>0 && destFilename[0] == '/') { destFilename.erase(0, 1); } - m_type = etk::FSN_TYPE_RELATIF; + m_type = etk::FSNType_relatif; } else if(start_with(destFilename, "~")) { TK_DBG_MODE(" ==> detect home 2"); destFilename.erase(0, 1); - m_type = etk::FSN_TYPE_HOME; + m_type = etk::FSNType_home; } else if( start_with(destFilename, "HOME:") == true || start_with(destFilename, "home:") == true ) { TK_DBG_MODE(" ==> detect home 3"); destFilename.erase(0, 5); - m_type = etk::FSN_TYPE_HOME; + m_type = etk::FSNType_home; if(start_with(destFilename, "~") == true) { destFilename.erase(0, 1); } } else if (start_with(destFilename, baseFolderHome) == true) { TK_DBG_MODE(" ==> detect home"); destFilename.erase(0, baseFolderHome.size()); - m_type = etk::FSN_TYPE_HOME; + m_type = etk::FSNType_home; } else if(isRootFolder == true) { TK_DBG_MODE(" ==> detect root"); #ifdef __TARGET_OS__Windows @@ -746,12 +746,12 @@ void etk::FSNode::privateSetName(std::string _newName) { #else destFilename.erase(0, 1); #endif - m_type = etk::FSN_TYPE_DIRECT; + m_type = etk::FSNType_direct; } else { TK_DBG_MODE(" ==> detect other"); // nothing to remove //Other type is Relative : - m_type = etk::FSN_TYPE_RELATIF; + m_type = etk::FSNType_relatif; } m_userFileName = destFilename; TK_DBG_MODE("3 : parse done : [" << m_type << "]->\"" << m_userFileName << "\""); @@ -778,7 +778,7 @@ void etk::FSNode::privateSetName(std::string _newName) { bool directCheckFile(std::string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { #ifdef HAVE_ZIP_DATA if (true == _checkInAPKIfNeeded) { - if( NULL != s_APKArchive + if( nullptr != s_APKArchive && true == s_APKArchive->exist(_tmpFileNameDirect) ) { return true; } @@ -806,13 +806,13 @@ void etk::FSNode::generateFileSystemPath() { } switch (m_type) { default: - case etk::FSN_TYPE_UNKNOW: + case etk::FSNType_unknow: m_systemFileName = baseFolderHome; break; - case etk::FSN_TYPE_DIRECT: + case etk::FSNType_direct: m_systemFileName = "/"; break; - case etk::FSN_TYPE_RELATIF: { + case etk::FSNType_relatif: { // Get the command came from the running of the program : char cCurrentPath[FILENAME_MAX]; if (!getcwd(cCurrentPath, FILENAME_MAX)) { @@ -825,10 +825,10 @@ void etk::FSNode::generateFileSystemPath() { //m_systemFileName += "/"; break; } - case etk::FSN_TYPE_HOME: + case etk::FSNType_home: m_systemFileName = baseFolderHome; break; - case etk::FSN_TYPE_DATA: + case etk::FSNType_data: { TK_DBG_MODE("DATA lib : \"" << m_libSearch << "\" => \"" << m_userFileName << "\" forceLib = " << forceLibFolder); // search the correct folder: @@ -847,14 +847,14 @@ void etk::FSNode::generateFileSystemPath() { return; } break; - case etk::FSN_TYPE_USER_DATA: + case etk::FSNType_userData: m_systemFileName = baseFolderDataUser; break; - case etk::FSN_TYPE_CACHE: + case etk::FSNType_cache: m_systemFileName = baseFolderCache; break; - case etk::FSN_TYPE_THEME: - case etk::FSN_TYPE_THEME_DATA: + case etk::FSNType_theme: + case etk::FSNType_themeData: { //std::u32string myCompleateName=baseFolderData + "/theme/"; std::string themeName(""); @@ -883,7 +883,7 @@ void etk::FSNode::generateFileSystemPath() { // check in the Appl data : m_systemFileName = simplifyPath(baseFolderData + "theme/" + themeName + "/" + basicName); if (directCheckFile(m_systemFileName, true) == true) { - m_type = etk::FSN_TYPE_THEME_DATA; + m_type = etk::FSNType_themeData; return; } } @@ -897,7 +897,7 @@ void etk::FSNode::generateFileSystemPath() { // check in the Appl data : m_systemFileName = simplifyPath(baseFolderData + "/../" + m_libSearch + "/theme/" + themeName + "/" + basicName); if (directCheckFile(m_systemFileName, true) == true) { - m_type = etk::FSN_TYPE_THEME_DATA; + m_type = etk::FSNType_themeData; return; } } @@ -912,11 +912,11 @@ void etk::FSNode::generateFileSystemPath() { // check in the Appl data : In every case we return this one ... m_systemFileName = simplifyPath(baseFolderData + "theme/" + themeNameDefault + "/" + basicName); if (true==directCheckFile(m_systemFileName, true)) { - m_type = etk::FSN_TYPE_THEME_DATA; + m_type = etk::FSNType_themeData; return; } if (m_libSearch.size() == 0) { - m_type = etk::FSN_TYPE_UNKNOW; + m_type = etk::FSNType_unknow; return; } } @@ -928,10 +928,10 @@ void etk::FSNode::generateFileSystemPath() { // check in the Appl data : In every case we return this one ... m_systemFileName = simplifyPath(baseFolderData + "/../" + m_libSearch + "/theme/" + themeNameDefault + "/" + basicName); if (true==directCheckFile(m_systemFileName, true)) { - m_type = etk::FSN_TYPE_THEME_DATA; + m_type = etk::FSNType_themeData; return; } - m_type = etk::FSN_TYPE_UNKNOW; + m_type = etk::FSNType_unknow; return; } break; @@ -956,11 +956,11 @@ void etk::FSNode::updateFileSystemProperty() { m_idOwner = 0; m_idGroup = 0; // File type is not knowns ... - m_typeNode=FSN_UNKNOW; + m_typeNode=typeNode_unknow; #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { // ---------------------------------------- // = Check if it was a folder : = // ---------------------------------------- @@ -971,12 +971,12 @@ void etk::FSNode::updateFileSystemProperty() { folderName = m_systemFileName + "/"; } // note : Zip does not support other think than file ... - if (s_APKArchive == NULL) { + if (s_APKArchive == nullptr) { TK_ERROR("NOT Find the File in APK : '" << m_systemFileName << "'"); return; } if (s_APKArchive->exist(m_systemFileName) == true) { - m_typeNode=FSN_FILE; + m_typeNode=typeNode_file; m_rights.setUserReadable(true); TK_DBG_MODE("Find a File in APK : '" << m_systemFileName << "'"); return; @@ -988,7 +988,7 @@ void etk::FSNode::updateFileSystemProperty() { for (int iii=0; iiisize(); iii++) { std::string filename = s_APKArchive->getName(iii); if (start_with(filename, m_systemFileName) == true) { - m_typeNode=etk::FSN_FOLDER; + m_typeNode=etk::typeNode_folder; m_rights.setUserReadable(true); m_rights.setUserRunable(true); TK_DBG_MODE("Find a Folder in APK : '" << m_systemFileName << "'"); @@ -1008,18 +1008,18 @@ void etk::FSNode::updateFileSystemProperty() { } switch (statProperty.st_mode & S_IFMT) { - case S_IFBLK: m_typeNode=etk::FSN_BLOCK; break; - case S_IFCHR: m_typeNode=etk::FSN_CHARACTER; break; - case S_IFDIR: m_typeNode=etk::FSN_FOLDER; break; - case S_IFIFO: m_typeNode=etk::FSN_FIFO; break; + case S_IFBLK: m_typeNode=etk::typeNode_block; break; + case S_IFCHR: m_typeNode=etk::typeNode_character; break; + case S_IFDIR: m_typeNode=etk::typeNode_folder; break; + case S_IFIFO: m_typeNode=etk::typeNode_fifo; break; #ifndef __TARGET_OS__Windows - case S_IFLNK: m_typeNode=etk::FSN_LINK; break; + case S_IFLNK: m_typeNode=etk::typeNode_link; break; #endif - case S_IFREG: m_typeNode=etk::FSN_FILE; break; + case S_IFREG: m_typeNode=etk::typeNode_file; break; #ifndef __TARGET_OS__Windows - case S_IFSOCK: m_typeNode=etk::FSN_SOCKET; break; + case S_IFSOCK: m_typeNode=etk::typeNode_socket; break; #endif - default: m_typeNode=etk::FSN_UNKNOW; break; + default: m_typeNode=etk::typeNode_unknow; break; } // Right m_rights = statProperty.st_mode; @@ -1078,29 +1078,29 @@ std::string etk::FSNode::getName() const { } switch (m_type) { default: - case etk::FSN_TYPE_UNKNOW: + case etk::FSNType_unknow: output += "HOME:"; break; - case etk::FSN_TYPE_DIRECT: + case etk::FSNType_direct: output += "/"; break; - case etk::FSN_TYPE_RELATIF: + case etk::FSNType_relatif: output += "REL:"; break; - case etk::FSN_TYPE_HOME: + case etk::FSNType_home: output += "~"; break; - case etk::FSN_TYPE_DATA: + case etk::FSNType_data: output += "DATA:"; break; - case etk::FSN_TYPE_USER_DATA: + case etk::FSNType_userData: output += "USERDATA:"; break; - case etk::FSN_TYPE_CACHE: + case etk::FSNType_cache: output += "CACHE:"; break; - case etk::FSN_TYPE_THEME: - case etk::FSN_TYPE_THEME_DATA: + case etk::FSNType_theme: + case etk::FSNType_themeData: output += "THEME:"; break; } @@ -1130,9 +1130,9 @@ std::string etk::FSNode::getRelativeFolder() const { std::string tmppp = getName(); TK_DBG_MODE("get REF folder : " << tmppp ); switch (m_typeNode) { - case etk::FSN_UNKNOW: - case etk::FSN_FOLDER: - case etk::FSN_LINK: + case etk::typeNode_unknow: + case etk::typeNode_folder: + case etk::typeNode_link: if (tmppp[tmppp.size()-1] == '/') { TK_DBG_MODE(" ==> : " << tmppp ); return tmppp; @@ -1143,11 +1143,11 @@ std::string etk::FSNode::getRelativeFolder() const { return tmpVal; } break; - case etk::FSN_BLOCK: - case etk::FSN_CHARACTER: - case etk::FSN_FIFO: - case etk::FSN_FILE: - case etk::FSN_SOCKET: + case etk::typeNode_block: + case etk::typeNode_character: + case etk::typeNode_fifo: + case etk::typeNode_file: + case etk::typeNode_socket: default: break; } @@ -1203,7 +1203,7 @@ bool etk::FSNode::move(const std::string& _path) { #endif bool etk::FSNode::remove() { - if (getNodeType()==etk::FSN_FOLDER) { + if (getNodeType()==etk::typeNode_folder) { // remove the folder if( 0!=rmdir(m_systemFileName.c_str()) ) { if (ENOTEMPTY == errno) { @@ -1282,17 +1282,17 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) { if( this == &_obj ) { return *this; } - if( NULL != m_PointerFile + if( nullptr != m_PointerFile #ifdef HAVE_ZIP_DATA - || NULL != m_zipContent + || nullptr != m_zipContent #endif ) { TK_ERROR("Missing close the file : " << *this); fileClose(); - m_PointerFile = NULL; + m_PointerFile = nullptr; } #ifdef HAVE_ZIP_DATA - m_zipContent = NULL; + m_zipContent = nullptr; m_zipReadingOffset = 0; #endif std::string tmppp = _obj.getName(); @@ -1328,32 +1328,32 @@ std::ostream& etk::operator <<(std::ostream &_os, const etk::FSNode &_obj) { std::ostream& etk::operator <<(std::ostream &_os, const enum etk::FSNType &_obj) { switch (_obj) { - case etk::FSN_TYPE_UNKNOW: - _os << "FSN_TYPE_UNKNOW"; + case etk::FSNType_unknow: + _os << "FSNType_unknow"; break; - case etk::FSN_TYPE_DIRECT: - _os << "FSN_TYPE_DIRECT"; + case etk::FSNType_direct: + _os << "FSNType_direct"; break; - case etk::FSN_TYPE_RELATIF: - _os << "FSN_TYPE_RELATIF"; + case etk::FSNType_relatif: + _os << "FSNType_relatif"; break; - case etk::FSN_TYPE_HOME: - _os << "FSN_TYPE_HOME"; + case etk::FSNType_home: + _os << "FSNType_home"; break; - case etk::FSN_TYPE_DATA: - _os << "FSN_TYPE_DATA"; + case etk::FSNType_data: + _os << "FSNType_data"; break; - case etk::FSN_TYPE_USER_DATA: - _os << "FSN_TYPE_USER_DATA"; + case etk::FSNType_userData: + _os << "FSNType_userData"; break; - case etk::FSN_TYPE_CACHE: - _os << "FSN_TYPE_CACHE"; + case etk::FSNType_cache: + _os << "FSNType_cache"; break; - case etk::FSN_TYPE_THEME: - _os << "FSN_TYPE_THEME"; + case etk::FSNType_theme: + _os << "FSNType_theme"; break; - case etk::FSN_TYPE_THEME_DATA: - _os << "FSN_TYPE_THEME(DATA)"; + case etk::FSNType_themeData: + _os << "FSNType_theme(DATA)"; break; default: _os << "FSN_TYPE_????"; @@ -1364,32 +1364,32 @@ std::ostream& etk::operator <<(std::ostream &_os, const enum etk::FSNType &_obj) std::ostream& etk::operator <<(std::ostream &_os, const enum etk::typeNode &_obj) { switch (_obj) { - case etk::FSN_UNKNOW: - _os << "FSN_UNKNOW"; + case etk::typeNode_unknow: + _os << "typeNode_unknow"; break; - case etk::FSN_BLOCK: - _os << "FSN_BLOCK"; + case etk::typeNode_block: + _os << "typeNode_block"; break; - case etk::FSN_CHARACTER: - _os << "FSN_CHARACTER"; + case etk::typeNode_character: + _os << "typeNode_character"; break; - case etk::FSN_FOLDER: - _os << "FSN_FOLDER"; + case etk::typeNode_folder: + _os << "typeNode_folder"; break; - case etk::FSN_FIFO: - _os << "FSN_FIFO"; + case etk::typeNode_fifo: + _os << "typeNode_fifo"; break; - case etk::FSN_LINK: - _os << "FSN_LINK"; + case etk::typeNode_link: + _os << "typeNode_link"; break; - case etk::FSN_FILE: - _os << "FSN_FILE"; + case etk::typeNode_file: + _os << "typeNode_file"; break; - case etk::FSN_SOCKET: - _os << "FSN_SOCKET"; + case etk::typeNode_socket: + _os << "typeNode_socket"; break; default: - _os << "FSN_????"; + _os << "typeNode_????"; break; } return _os; @@ -1400,12 +1400,12 @@ std::ostream& etk::operator <<(std::ostream &_os, const enum etk::typeNode &_obj */ int64_t etk::FSNode::folderCount() { int64_t counter=0; - DIR *dir = NULL; - struct dirent *ent = NULL; + DIR *dir = nullptr; + struct dirent *ent = nullptr; dir = opendir(m_systemFileName.c_str()); - if (dir != NULL) { + if (dir != nullptr) { // for each element in the drectory... - while ((ent = readdir(dir)) != NULL) { + while ((ent = readdir(dir)) != nullptr) { std::string tmpName(ent->d_name); if( tmpName == "." || tmpName == ".." ) { @@ -1434,17 +1434,17 @@ std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo TK_TODO("implement filter ... "); std::vector tmpp; // regenerate the next list : - etk::FSNode * tmpEmement = NULL; - if (m_typeNode != etk::FSN_FOLDER ) { + etk::FSNode * tmpEmement = nullptr; + if (m_typeNode != etk::typeNode_folder ) { return tmpp; } #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { std::vector listAdded; std::string assetsName = baseFolderData; std::string FolderName = getNameFolder(); - if (s_APKArchive==NULL) { + if (s_APKArchive==nullptr) { return tmpp; } for (int iii=0; iiisize(); iii++) { @@ -1467,25 +1467,25 @@ std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo if (findIt == false) { listAdded.push_back(tmpString); tmpEmement = new etk::FSNode(tmpString); - if (NULL == tmpEmement) { + if (nullptr == tmpEmement) { TK_ERROR("allocation error ... of ewol::FSNode"); continue; } TK_VERBOSE("find element : '" << tmpString << "' --> " << *tmpEmement); tmpp.push_back(tmpEmement); - tmpEmement = NULL; + tmpEmement = nullptr; } } } return tmpp; } #endif - DIR *dir = NULL; - struct dirent *ent = NULL; + DIR *dir = nullptr; + struct dirent *ent = nullptr; dir = opendir(m_systemFileName.c_str()); - if (dir != NULL) { + if (dir != nullptr) { // for each element in the drectory... - while ((ent = readdir(dir)) != NULL) { + while ((ent = readdir(dir)) != nullptr) { std::string tmpName(ent->d_name); TK_VERBOSE(" search in folder\"" << tmpName << "\""); if( tmpName == "." @@ -1496,22 +1496,22 @@ std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo if( false == start_with(tmpName, ".") || true == _showHidenFile) { tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); - if (NULL == tmpEmement) { + if (nullptr == tmpEmement) { TK_ERROR("allocation error ... of ewol::FSNode"); continue; } - if(tmpEmement->getNodeType() == etk::FSN_FILE) { + if(tmpEmement->getNodeType() == etk::typeNode_file) { if (true == _getFile) { tmpp.push_back(tmpEmement); } else { delete(tmpEmement); - tmpEmement = NULL; + tmpEmement = nullptr; } } else if (_getFolderAndOther) { tmpp.push_back(tmpEmement); } else { delete(tmpEmement); - tmpEmement = NULL; + tmpEmement = nullptr; } } } @@ -1533,18 +1533,18 @@ etk::FSNode etk::FSNode::folderGetParent() { void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { std::string assetsName = baseFolderData; std::string FolderName = getNameFolder(); - if (s_APKArchive==NULL) { + if (s_APKArchive==nullptr) { return; } for (int iii=0; iiisize(); iii++) { std::string filename = s_APKArchive->getName(iii); if (start_with(filename, FolderName) == true) { std::string tmpString; - if(m_type == etk::FSN_TYPE_DATA) { + if(m_type == etk::FSNType_data) { tmpString = "DATA:"; } else { tmpString = "THEME:"; @@ -1561,13 +1561,13 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, boo #endif // regenerate the next list : etk::FSNode * tmpEmement; - DIR *dir = NULL; - struct dirent *ent = NULL; + DIR *dir = nullptr; + struct dirent *ent = nullptr; dir = opendir(m_systemFileName.c_str()); //TK_DEBUG(" ** open Folder : " << m_systemFileName ); - if (dir != NULL) { + if (dir != nullptr) { // for each element in the drectory... - while ((ent = readdir(dir)) != NULL) { + while ((ent = readdir(dir)) != nullptr) { std::string tmpName(ent->d_name); if( tmpName == "." || tmpName == ".." ) { @@ -1576,18 +1576,18 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, boo } //TK_DEBUG(" find : " << ent->d_name << " ==> " << (GetRelativeFolder()+tmpName)); tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); - if (NULL != tmpEmement) { - if(tmpEmement->getNodeType() == etk::FSN_FILE) { + if (nullptr != tmpEmement) { + if(tmpEmement->getNodeType() == etk::typeNode_file) { std::string tmpVal = tmpEmement->getName(); _output.push_back(tmpVal); } - if(tmpEmement->getNodeType() == etk::FSN_FOLDER) { + if(tmpEmement->getNodeType() == etk::typeNode_folder) { if (true==_recursiveEnable) { tmpEmement->folderGetRecursiveFiles(_output, _recursiveEnable); } } delete(tmpEmement); - tmpEmement = NULL; + tmpEmement = nullptr; } else { TK_ERROR("allocation error ... of ewol::FSNode"); continue; @@ -1639,13 +1639,13 @@ std::string etk::FSNode::fileGetExtention() { #endif uint64_t etk::FSNode::fileSize() { - if (etk::FSN_FILE != m_typeNode) { + if (etk::typeNode_file != m_typeNode) { TK_ERROR("Request size of a non file node : " << m_typeNode); return 0; } #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { if (true == loadDataZip()) { return m_zipContent->getTheoricSize(); } @@ -1670,8 +1670,8 @@ uint64_t etk::FSNode::fileSize() { bool etk::FSNode::fileOpenRead() { #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { if (false==loadDataZip()) { return false; } @@ -1680,13 +1680,13 @@ bool etk::FSNode::fileOpenRead() { return m_zipContent->getTheoricSize() == m_zipContent->size(); } #endif - if (NULL != m_PointerFile) { + if (nullptr != m_PointerFile) { TK_CRITICAL("File Already open : " << *this); return true; } TK_VERBOSE(" Read file : " << m_systemFileName); m_PointerFile=fopen(m_systemFileName.c_str(),"rb"); - if(NULL == m_PointerFile) { + if(nullptr == m_PointerFile) { TK_ERROR("Can not find the file " << *this ); return false; } @@ -1694,19 +1694,19 @@ bool etk::FSNode::fileOpenRead() { } bool etk::FSNode::fileOpenWrite() { #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { return false; } #endif - if (NULL != m_PointerFile) { + if (nullptr != m_PointerFile) { TK_CRITICAL("File Already open : " << *this); return true; } FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777); TK_VERBOSE(" write file : " << m_systemFileName); m_PointerFile=fopen(m_systemFileName.c_str(),"wb"); - if(NULL == m_PointerFile) { + if(nullptr == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; } @@ -1715,12 +1715,12 @@ bool etk::FSNode::fileOpenWrite() { bool etk::FSNode::fileOpenAppend() { #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { return false; } #endif - if (NULL != m_PointerFile) { + if (nullptr != m_PointerFile) { TK_CRITICAL("File Already open : " << *this); return true; } @@ -1729,7 +1729,7 @@ bool etk::FSNode::fileOpenAppend() { TK_VERBOSE(" append file : " << m_systemFileName); m_PointerFile=fopen(m_systemFileName.c_str(),"ab"); - if(NULL == m_PointerFile) { + if(nullptr == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; } @@ -1738,39 +1738,39 @@ bool etk::FSNode::fileOpenAppend() { bool etk::FSNode::fileIsOpen() { #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { - if (m_zipContent == NULL) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { + if (m_zipContent == nullptr) { return false; } return true; } #endif - if (m_PointerFile == NULL) { + if (m_PointerFile == nullptr) { return false; } return true; } bool etk::FSNode::fileClose() { #ifdef HAVE_ZIP_DATA - if( etk::FSN_TYPE_DATA == m_type - || etk::FSN_TYPE_THEME_DATA == m_type) { - if (m_zipContent == NULL) { + if( etk::FSNType_data == m_type + || etk::FSNType_themeData == m_type) { + if (m_zipContent == nullptr) { TK_CRITICAL("File Already closed : " << *this); return false; } s_APKArchive->close(m_systemFileName); - m_zipContent = NULL; + m_zipContent = nullptr; m_zipReadingOffset = 0; return true; } #endif - if (m_PointerFile == NULL) { + if (m_PointerFile == nullptr) { TK_CRITICAL("File Already closed : " << *this); return false; } fclose(m_PointerFile); - m_PointerFile = NULL; + m_PointerFile = nullptr; return true; } @@ -1779,15 +1779,15 @@ char* etk::FSNode::fileGets(char* _elementLine, int64_t _maxData) { #ifdef HAVE_ZIP_DATA char * element = _elementLine; int64_t outSize = 0; - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; - if (m_zipContent == NULL) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset; + if (m_zipContent == nullptr) { element[0] = '\0'; - return NULL; + return nullptr; } if (m_zipReadingOffset >= m_zipContent->size()) { element[0] = '\0'; - return NULL; + return nullptr; } while (((char*)m_zipContent->data())[m_zipReadingOffset] != '\0') { if( ((char*)m_zipContent->data())[m_zipReadingOffset] == '\n' @@ -1813,7 +1813,7 @@ char* etk::FSNode::fileGets(char* _elementLine, int64_t _maxData) { outSize++; } if (outSize==0) { - return NULL; + return nullptr; } else { // send last line return _elementLine; @@ -1847,9 +1847,9 @@ bool etk::FSNode::fileGets(std::string& _output) { int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock) { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { - if (m_zipContent == NULL) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { + if (m_zipContent == nullptr) { ((char*)_data)[0] = '\0'; return 0; } @@ -1882,8 +1882,8 @@ bool etk::FSNode::filePuts(const std::string& _input) { int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _nbBlock) { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { TK_CRITICAL("Can not write on data inside APK : " << *this); return 0; } @@ -1934,17 +1934,17 @@ etk::FSNode& etk::FSNode::operator<< (const float _data) { bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { - if (NULL == m_zipContent) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { + if (nullptr == m_zipContent) { return false; } int32_t positionEnd = 0; switch(_origin) { - case etk::FSN_SEEK_END: + case etk::seekNode_end: positionEnd = m_zipContent->size(); break; - case etk::FSN_SEEK_CURRENT: + case etk::seekNode_current: positionEnd = m_zipReadingOffset; break; default: @@ -1963,10 +1963,10 @@ bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) #endif int originFS = 0; switch(_origin) { - case etk::FSN_SEEK_END: + case etk::seekNode_end: originFS = SEEK_END; break; - case etk::FSN_SEEK_CURRENT: + case etk::seekNode_current: originFS = SEEK_CUR; break; default: @@ -1982,9 +1982,9 @@ bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin) } int64_t etk::FSNode::fileTell() { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { - if (NULL == m_zipContent) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { + if (nullptr == m_zipContent) { return false; } return m_zipReadingOffset; @@ -1996,12 +1996,12 @@ int64_t etk::FSNode::fileTell() { void etk::FSNode::fileFlush() { #ifdef HAVE_ZIP_DATA - if( m_type == etk::FSN_TYPE_DATA - || m_type == etk::FSN_TYPE_THEME_DATA) { + if( m_type == etk::FSNType_data + || m_type == etk::FSNType_themeData) { return; } #endif - if (m_PointerFile != NULL) { + if (m_PointerFile != nullptr) { fflush(m_PointerFile); } } @@ -2241,7 +2241,7 @@ bool etk::FSNodeEcho(const std::string& _path, const std::string& _dataTowrite) if (false==tmpNode.exist()) { return false; } - if (FSN_FOLDER==tmpNode.getNodeType()) { + if (typeNode_folder==tmpNode.getNodeType()) { return false; } if (false==tmpNode.fileOpenWrite()) { @@ -2265,7 +2265,7 @@ bool etk::FSNodeEchoAdd(const std::string& _path, const std::string& _dataTowrit if (false==tmpNode.exist()) { return false; } - if (FSN_FOLDER==tmpNode.getNodeType()) { + if (typeNode_folder==tmpNode.getNodeType()) { return false; } if (false==tmpNode.fileOpenAppend()) { diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index 077a1da..13ffe19 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -11,7 +11,9 @@ #pragma once #include - +/** + * @brief Local maximum file name size + */ #define MAX_FILE_NAME (10240) //http://developer.android.com/guide/topics/data/data-storage.html @@ -32,76 +34,88 @@ namespace etk { } #endif namespace etk { + /** + * @brief Set the firt argument of the application start (this permit to get the real position of the execution path and executable position + * @param[in] _val First parameter. + */ void setArgZero(const std::string& _val); + /** + * @brief Simplify a path with all the complication that mean ".." or "///\//" + * @param[in] _input Parth to simplify + * @return the simplified path. + */ std::string simplifyPath(std::string _input); - /** * @brief Get application name. * @return The application name */ std::string FSNodeGetApplicationName(); /** - * List of Type that a node can have (this wrap some type that not exist on Windows) + * @brief List of Type that a node can have (this wrap some type that not exist on Windows) */ enum typeNode { - FSN_UNKNOW, //!< Type of the node is not known - FSN_BLOCK, //!< The node is a block aceess device (Not availlable on Windows) - FSN_CHARACTER, //!< The node is a Char device type (Not availlable on Windows) - FSN_FOLDER, //!< The node is a folder - FSN_FIFO, //!< The node is a Fifo (Not availlable on Windows) - FSN_LINK, //!< The node is a Link - FSN_FILE, //!< The node is a File - FSN_SOCKET, //!< The node is a socket + typeNode_unknow, //!< Type of the node is not known + typeNode_block, //!< The node is a block aceess device (Not availlable on Windows) + typeNode_character, //!< The node is a Char device type (Not availlable on Windows) + typeNode_folder, //!< The node is a folder + typeNode_fifo, //!< The node is a Fifo (Not availlable on Windows) + typeNode_link, //!< The node is a Link + typeNode_file, //!< The node is a File + typeNode_socket, //!< The node is a socket }; - + //! @not_in_doc std::ostream& operator <<(std::ostream &_os, const enum etk::typeNode &_obj); - + /** + * @brief Seek mode availlable (just to wrap it ...) + */ enum seekNode{ - FSN_SEEK_START, - FSN_SEEK_END, - FSN_SEEK_CURRENT, + seekNode_start, //!< request seek position start at the START of the file + seekNode_end, //!< request seek position start at the END of the file + seekNode_current, //!< request seek position start at the CURRENT position in the file }; - + /** + * @brief Type of the file/folder/... accessible in the Node + */ enum FSNType { - FSN_TYPE_UNKNOW, + FSNType_unknow, //!< Unknow type of the node (many time no file name seted) // user might done abstraction ==> acces of the sdcard when possible ... - FSN_TYPE_DIRECT, - FSN_TYPE_RELATIF, + FSNType_direct, //!< Access at the file System with a direct naming like "/home/plop/xxx.txt" + FSNType_relatif, //!< Access at the file System with a relative naming like "../plop/xxx.txt" // depend on case // - PC : ~/ // - Android : /sdcard/ // - Apple : ???? - FSN_TYPE_HOME, + FSNType_home, //!< acces at the home path of the system (with name of the current user) // depend of the case // - PC : /usr/shared/programName/ // - Android : Internal at the executable file (pointer on static area) // - Apple : Internal at the executable file - FSN_TYPE_DATA, + FSNType_data, //!< Access on the application data (internal application data are the one provided with the binary) // depend on case // - PC : ~/.local/programName/ // - Android : /data/data/programName/files/ // - Apple : ???? - FSN_TYPE_USER_DATA, + FSNType_userData, //!< Access on the user application data (where the data are stored when the application stop) // depend on case // - PC : ~/.programName/cache/ // - Android : /data/data/programName/cache/ // - Apple : ???? - FSN_TYPE_CACHE, + FSNType_cache, //!< Access on the application temporary path (remove when user want and whe the compter restart or have not enought memory) // depend on case - // - try on FSN_TYPE_USER_DATA:/theme/themeName/xxx - // - try on FSN_TYPE_DATA:/theme/themeName/xxx + // - try on USER_DATA:/theme/themeName/xxx + // - try on DATA:/theme/themeName/xxx // and jump to the default theme file - // - try on FSN_TYPE_USER_DATA:/theme/default/xxx - // - try on FSN_TYPE_DATA:/theme/default/xxx - FSN_TYPE_THEME, - FSN_TYPE_THEME_DATA + // - try on USER_DATA:/theme/default/xxx + // - try on DATA:/theme/default/xxx + FSNType_theme, //!< Theme area + FSNType_themeData //!< Theme data area }; - + //! @not_in_doc std::ostream& operator <<(std::ostream &_os, const enum etk::FSNType &_obj); /* @@ -144,7 +158,9 @@ namespace etk { ./ */ /** - * @brief FS node is for File system IO access This class is independent of the OS, If you acces to a file in windows, it might generate the right loke Linux (it is important to know that windows right is lighter than linux) + * @brief FS node is for File System IO access (named classicly "node in linux EXT) + * This class is independent of the OS, If you acces to a file in windows, it might + * generate the right like Linux (it is important to know that windows right is lighter than linux) */ class FSNode { private: @@ -210,11 +226,11 @@ namespace etk { * @return false : The node does not exist. */ bool exist() const { - return (m_typeNode!=etk::FSN_UNKNOW); + return (m_typeNode!=etk::typeNode_unknow); }; /** * @brief Get the node type - * @return the requested type, FSN_UNKNOW if it does not existed + * @return the requested type, typeNode_unknow if it does not existed */ enum typeNode getNodeType() const { return m_typeNode; @@ -234,10 +250,10 @@ namespace etk { */ bool setRight(etk::FSNodeRight _newRight); /** - * @brief Change the Node seeing (not rename the node, for this @ref Move) + * @brief Change the Node seeing (not rename the node, for this @ref etk::FSNodeMove) * @param[in] _newName New node name to show - * @return true : action done - * @return false : action not done + * @return true action done + * @return false action not done */ void setName(const std::string& _newName); #if __CPP_VERSION__ >= 2011 @@ -398,6 +414,14 @@ namespace etk { bool _getFolderAndOther = true, bool _getFile = true, bool _temporaryFile = true); + /** + * @brief Get the List of all node inside a node (folder only) + * @param[in] _showHidenFile Add hidden file/folder/... + * @param[in] _getFolderAndOther get folder + * @param[in] _getFile Get files + * @param[in] _filter Generic regex string to filter file names + * @return The requested list + */ std::vector folderGetSubList(bool _showHidenFile = true, bool _getFolderAndOther = true, bool _getFile = true, @@ -516,17 +540,23 @@ namespace etk { * @return Number of element written (in block number) */ int64_t fileWrite(const void* _data, int64_t _blockSize, int64_t _nbBlock); + // TODO: etk::FSNode& operator<< (const std::ostream& _data); /** * @brief Stream write mode * @param[in] _data Stream to write + * @return The current FSNode reference to add other stream. * @note not stable API ... */ - //etk::FSNode& operator<< (const std::ostream& _data); etk::FSNode& operator<< (const std::stringstream& _data); + //! @copydoc etk::FSNode::operator<<(const std::stringstream&) etk::FSNode& operator<< (const std::string& _data); + //! @copydoc etk::FSNode::operator<<(const std::stringstream&) etk::FSNode& operator<< (const char* _data); + //! @copydoc etk::FSNode::operator<<(const std::stringstream&) etk::FSNode& operator<< (const int32_t _data); + //! @copydoc etk::FSNode::operator<<(const std::stringstream&) etk::FSNode& operator<< (const uint32_t _data); + //! @copydoc etk::FSNode::operator<<(const std::stringstream&) etk::FSNode& operator<< (const float _data); /** * @brief Get the position in the file. @@ -555,6 +585,10 @@ namespace etk { fileRead(&value[0], sizeof(T), fileSize()/sizeof(T)); return value; } + /** + * @brief Read all element in a file and set it in a generic std::string + * @return the read string + */ std::string fileReadAllString() { std::string value; value.resize(fileSize()); @@ -568,10 +602,16 @@ namespace etk { #endif /** * @brief Write all the vector in a file + * @param[in] _value Data to write in the File */ - template void fileWriteAll(const std::vector& _value) { + template + void fileWriteAll(const std::vector& _value) { fileWrite(static_cast(&(_value[0])), sizeof(T), _value.size()/sizeof(T)); } + /** + * @brief Write all the vector in a file + * @param[in] _value String data to write in the File + */ void fileWriteAll(const std::string& _value) { fileWrite(static_cast(&(_value[0])), sizeof(char), _value.size()/sizeof(char)); } @@ -587,7 +627,7 @@ namespace etk { */ void sortElementList(std::vector& _list); }; - + //! @not_in_doc std::ostream& operator <<(std::ostream &_os, const etk::FSNode &_obj); /** @@ -709,9 +749,9 @@ namespace etk { * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); + bool FSNodeCreate(const std::string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder); #if __CPP_VERSION__ >= 2011 - bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); + bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder); #endif /** * @brief Simple access for : chexk the exestance of an element diff --git a/etk/os/FSNodeRight.cpp b/etk/os/FSNodeRight.cpp index 58975f1..8fd788d 100644 --- a/etk/os/FSNodeRight.cpp +++ b/etk/os/FSNodeRight.cpp @@ -11,167 +11,146 @@ // Right Flags : enum { - RIGHT_OTHER_EXECUTE = 1 << 0, - RIGHT_OTHER_WRITE = 1 << 1, - RIGHT_OTHER_READ = 1 << 2, - RIGHT_GROUP_EXECUTE = 1 << 3, - RIGHT_GROUP_WRITE = 1 << 4, - RIGHT_GROUP_READ = 1 << 5, - RIGHT_USER_EXECUTE = 1 << 6, - RIGHT_USER_WRITE = 1 << 7, - RIGHT_USER_READ = 1 << 8, + right_other_execute = 1 << 0, + right_other_write = 1 << 1, + right_other_read = 1 << 2, + right_group_execute = 1 << 3, + right_group_write = 1 << 4, + right_group_read = 1 << 5, + right_user_execute = 1 << 6, + right_user_write = 1 << 7, + right_user_read = 1 << 8, }; etk::FSNodeRight::FSNodeRight() : - m_rights(0) -{ + m_rights(0) { } + etk::FSNodeRight::FSNodeRight(int16_t _newRight) : - m_rights(_newRight&0x01FF) -{ + m_rights(_newRight&0x01FF) { } -// copy operator : -const etk::FSNodeRight& etk::FSNodeRight::operator= (const etk::FSNodeRight &_obj ) -{ + +etk::FSNodeRight& etk::FSNodeRight::operator= (const etk::FSNodeRight &_obj ) { m_rights = _obj.m_rights; return *this; } -// set right : -const etk::FSNodeRight& etk::FSNodeRight::operator= (const int32_t _newVal ) -{ +etk::FSNodeRight& etk::FSNodeRight::operator= (const int32_t _newVal) { m_rights = _newVal&0x01FF; return *this; } -// User -bool etk::FSNodeRight::isUserReadable() const -{ - return ((m_rights&RIGHT_USER_READ)!=0)?true:false; +void etk::FSNodeRight::clear() { + m_rights = 0; } -bool etk::FSNodeRight::isUserWritable() const -{ - return ((m_rights&RIGHT_USER_WRITE)!=0)?true:false; +bool etk::FSNodeRight::isUserReadable() const { + return ((m_rights&right_user_read)!=0)?true:false; } -bool etk::FSNodeRight::isUserRunable() const -{ - return ((m_rights&RIGHT_USER_EXECUTE)!=0)?true:false; +bool etk::FSNodeRight::isUserWritable() const { + return ((m_rights&right_user_write)!=0)?true:false; } -void etk::FSNodeRight::setUserReadable(bool _newStatus) -{ +bool etk::FSNodeRight::isUserRunable() const { + return ((m_rights&right_user_execute)!=0)?true:false; +} + +void etk::FSNodeRight::setUserReadable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_USER_READ); - if (true == _newStatus) { - m_rights |= RIGHT_USER_READ; + m_rights &= (0xFFFFFFFF - right_user_read); + if (_newStatus == true) { + m_rights |= right_user_read; } } -void etk::FSNodeRight::setUserWritable(bool _newStatus) -{ +void etk::FSNodeRight::setUserWritable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_USER_WRITE); - if (true == _newStatus) { - m_rights |= RIGHT_USER_WRITE; + m_rights &= (0xFFFFFFFF - right_user_write); + if (_newStatus == true) { + m_rights |= right_user_write; } } -void etk::FSNodeRight::setUserRunable(bool _newStatus) -{ +void etk::FSNodeRight::setUserRunable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_USER_EXECUTE); - if (true == _newStatus) { - m_rights |= RIGHT_USER_EXECUTE; + m_rights &= (0xFFFFFFFF - right_user_execute); + if (_newStatus == true) { + m_rights |= right_user_execute; } } -// group -bool etk::FSNodeRight::isGroupReadable() const -{ - return ((m_rights&RIGHT_GROUP_READ)!=0)?true:false; +bool etk::FSNodeRight::isGroupReadable() const { + return ((m_rights&right_group_read)!=0)?true:false; } -bool etk::FSNodeRight::isGroupWritable() const -{ - return ((m_rights&RIGHT_GROUP_WRITE)!=0)?true:false; +bool etk::FSNodeRight::isGroupWritable() const { + return ((m_rights&right_group_write)!=0)?true:false; } -bool etk::FSNodeRight::isGroupRunable() const -{ - return ((m_rights&RIGHT_GROUP_EXECUTE)!=0)?true:false; +bool etk::FSNodeRight::isGroupRunable() const { + return ((m_rights&right_group_execute)!=0)?true:false; } -void etk::FSNodeRight::setGroupReadable(bool _newStatus) -{ +void etk::FSNodeRight::setGroupReadable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_GROUP_READ); + m_rights &= (0xFFFFFFFF - right_group_read); if (true == _newStatus) { - m_rights |= RIGHT_GROUP_READ; + m_rights |= right_group_read; } } -void etk::FSNodeRight::setGroupWritable(bool _newStatus) -{ +void etk::FSNodeRight::setGroupWritable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_GROUP_WRITE); + m_rights &= (0xFFFFFFFF - right_group_write); if (true == _newStatus) { - m_rights |= RIGHT_GROUP_WRITE; + m_rights |= right_group_write; } } -void etk::FSNodeRight::setGroupRunable(bool _newStatus) -{ +void etk::FSNodeRight::setGroupRunable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_GROUP_EXECUTE); + m_rights &= (0xFFFFFFFF - right_group_execute); if (true == _newStatus) { - m_rights |= RIGHT_GROUP_EXECUTE; + m_rights |= right_group_execute; } } -// other -bool etk::FSNodeRight::isOtherReadable() const -{ - return ((m_rights&RIGHT_OTHER_READ) != 0)?true:false; +bool etk::FSNodeRight::isOtherReadable() const { + return ((m_rights&right_other_read) != 0)?true:false; } -bool etk::FSNodeRight::isOtherWritable() const -{ - return ((m_rights&RIGHT_OTHER_WRITE) != 0)?true:false; +bool etk::FSNodeRight::isOtherWritable() const { + return ((m_rights&right_other_write) != 0)?true:false; } -bool etk::FSNodeRight::isOtherRunable() const -{ - return ((m_rights&RIGHT_OTHER_EXECUTE) != 0)?true:false; +bool etk::FSNodeRight::isOtherRunable() const { + return ((m_rights&right_other_execute) != 0)?true:false; } -void etk::FSNodeRight::setOtherReadable(bool _newStatus) -{ - // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_OTHER_READ); - if (true == _newStatus) { - m_rights |= RIGHT_OTHER_READ; +void etk::FSNodeRight::setOtherReadable(bool _newStatus) { + // reset the flag: + m_rights &= (0xFFFFFFFF - right_other_read); + if (_newStatus == true) { + m_rights |= right_other_read; } } -void etk::FSNodeRight::setOtherWritable(bool _newStatus) -{ +void etk::FSNodeRight::setOtherWritable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_OTHER_WRITE); - if (true == _newStatus) { - m_rights |= RIGHT_OTHER_WRITE; + m_rights &= (0xFFFFFFFF - right_other_write); + if (_newStatus == true) { + m_rights |= right_other_write; } } -void etk::FSNodeRight::setOtherRunable(bool _newStatus) -{ +void etk::FSNodeRight::setOtherRunable(bool _newStatus) { // reset the flag : - m_rights &= (0xFFFFFFFF - RIGHT_OTHER_EXECUTE); - if (true == _newStatus) { - m_rights |= RIGHT_OTHER_EXECUTE; + m_rights &= (0xFFFFFFFF - right_other_execute); + if (_newStatus == true) { + m_rights |= right_other_execute; } } #if __CPP_VERSION__ >= 2011 diff --git a/etk/os/FSNodeRight.h b/etk/os/FSNodeRight.h index 9bde67f..f58d994 100644 --- a/etk/os/FSNodeRight.h +++ b/etk/os/FSNodeRight.h @@ -11,45 +11,144 @@ #pragma once namespace etk { + /** + * @brief File System Right management + */ class FSNodeRight { private: - uint16_t m_rights; + uint16_t m_rights; //!< right manage in a bit field public: - FSNodeRight(); - FSNodeRight(int16_t _newRight); - ~FSNodeRight() { }; - // copy operator : - const etk::FSNodeRight& operator= (const etk::FSNodeRight &_obj ); - // set right : - const etk::FSNodeRight& operator= (const int32_t _newVal ); - - void clear() { - m_rights = 0; - }; - // User + /** + * @brief Right contructor. + * @param[in] _newRight Right to set by default + */ + FSNodeRight(int16_t _newRight = 0); + /** + * @brief Copy asignement operator (operator=) + * @param[in] _obj Object to copy + * @return Local reference on the object + */ + etk::FSNodeRight& operator= (const etk::FSNodeRight &_obj); + /** + * @brief Asignement operator (operator=) + * @param[in] _newVal Value to set on the right + * @return Local reference on the object + */ + etk::FSNodeRight& operator= (const int32_t _newVal ); + /** + * @brief Clear right (set the value at 0 ==> cant not be read/write/execute + */ + void clear(); + /** + * @brief Get the "Read status" for the "User" + * @return true The file/folder/... is readable + * @return false The file/folder/... is NOT readable + */ bool isUserReadable() const; + /** + * @brief Get the "Write status" for the "User" + * @return true The file/folder/... is writable + * @return false The file/folder/... is NOT writable + */ bool isUserWritable() const; + /** + * @brief Get the "execute status" for the "User" + * @return true The file/folder/... is executable + * @return false The file/folder/... is NOT executable + */ bool isUserRunable() const; + /** + * @brief Set the "Read status" for the "User" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setUserReadable(bool _newStatus); + /** + * @brief Set the "Write status" for the "User" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setUserWritable(bool _newStatus); + /** + * @brief Set the "execute status" for the "User" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setUserRunable(bool _newStatus); - // group + /** + * @brief Get the "Read status" for the "Group" + * @return true The file/folder/... is readable + * @return false The file/folder/... is NOT readable + */ bool isGroupReadable() const; + /** + * @brief Get the "Write status" for the "Group" + * @return true The file/folder/... is writable + * @return false The file/folder/... is NOT writable + */ bool isGroupWritable() const; + /** + * @brief Get the "execute status" for the "Group" + * @return true The file/folder/... is executable + * @return false The file/folder/... is NOT executable + */ bool isGroupRunable() const; + /** + * @brief Set the "Read status" for the "Group" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setGroupReadable(bool _newStatus); + /** + * @brief Set the "Write status" for the "Group" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setGroupWritable(bool _newStatus); + /** + * @brief Set the "Execute status" for the "Group" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setGroupRunable(bool _newStatus); - // other + /** + * @brief Get the "Read status" for the "Other" + * @return true The file/folder/... is readable + * @return false The file/folder/... is NOT readable + */ bool isOtherReadable() const; + /** + * @brief Get the "Write status" for the "Other" + * @return true The file/folder/... is writable + * @return false The file/folder/... is NOT writable + */ bool isOtherWritable() const; + /** + * @brief Get the "execute status" for the "Other" + * @return true The file/folder/... is executable + * @return false The file/folder/... is NOT executable + */ bool isOtherRunable() const; + /** + * @brief Set the "Read status" for the "Other" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setOtherReadable(bool _newStatus); + /** + * @brief Set the "Write status" for the "Other" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setOtherWritable(bool _newStatus); + /** + * @brief Set the "Execute status" for the "Other" + * @param[in] _newStatus New value to set on the file/folder/... + */ void setOtherRunable(bool _newStatus); #if __CPP_VERSION__ >= 2011 + /** + * @brief Get the write written in a string mode (like in linux rw-r-----) + * @return String with the right in string + */ std::u32string getURight() const; #endif + /** + * @brief Get the write written in a string mode (like in linux rw-r-----) + * @return String with the right in string + */ std::string getRight() const; }; //! @not_in_doc diff --git a/etk/os/Fifo.h b/etk/os/Fifo.h index 979241e..e53acbc 100644 --- a/etk/os/Fifo.h +++ b/etk/os/Fifo.h @@ -103,7 +103,10 @@ namespace etk { m_data.push_back(_data); m_condition.notify_all(); }; - //! @previous + /** + * @brief Send a message at the other thread by setting a new message in the fifo. + * @param[in] _data New data to add at the fifo. + */ void post(const MY_TYPE &_data) { std::unique_lock lock(m_mutex); m_data.push_back(_data); diff --git a/etk/stdTools.cpp b/etk/stdTools.cpp index 18b043a..14ae8cb 100644 --- a/etk/stdTools.cpp +++ b/etk/stdTools.cpp @@ -9,8 +9,6 @@ #include #include -#undef __class__ -#define __class__ "u32char" const char32_t u32char::Null('\0'); const char32_t u32char::Return('\n'); @@ -137,10 +135,6 @@ int8_t u32char::convertUtf8(char32_t _val, char _output[5]) { } #endif -#undef __class__ -#define __class__ "utf8" - - static uint8_t sizeElement(const char* _data, int32_t _lenMax) { uint8_t size = 0; TK_ASSERT(0 <= _lenMax, "size can not be < 0 ..."); @@ -309,8 +303,6 @@ char32_t utf8::iterator::operator* () { } -#undef __class__ -#define __class__ "etk" namespace etk { #if __CPP_VERSION__ >= 2011 template<> std::string to_string(const std::u32string& _input) { diff --git a/etk/stdTools.h b/etk/stdTools.h index 5e5ff9c..6fd8e70 100644 --- a/etk/stdTools.h +++ b/etk/stdTools.h @@ -16,35 +16,66 @@ #include #include +/** + * @brief Unicode simple wrapper interface + */ namespace u32char { - extern const char32_t Null; //!< '\0' - extern const char32_t Return; //!< '\n' - extern const char32_t CarrierReturn; //!< '\r' CR - extern const char32_t Tabulation; //!< '\t' TAB - extern const char32_t Suppress; //!< BS (SUPPRESS) - extern const char32_t Delete; //!< DEL - extern const char32_t Space; //!< ' ' SPACE - extern const char32_t Escape; //!< ESC Escape + extern const char32_t Null; //!< Value '\\0' + extern const char32_t Return; //!< Value '\\n' + extern const char32_t CarrierReturn; //!< Value '\\r' CR + extern const char32_t Tabulation; //!< Value '\\t' TAB + extern const char32_t Suppress; //!< Value BS (SUPPRESS) + extern const char32_t Delete; //!< Value DEL + extern const char32_t Space; //!< Value ' ' SPACE + extern const char32_t Escape; //!< Value ESC Escape /** - * @brief check if the current element is white or not : '\t' '\n' '\r' ' ' - * @return tue if it is white char + * @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' ' + * @param[in] _val Value to interprete + * @return true if it is white char + * @return false otherwise */ bool isWhiteChar(char32_t _val); + /** + * @brief check if the current element is NOT [a-zA-Z0-9] + * @param[in] _val Value to interprete + * @return true Not in the previous list + * @return false otherwise + */ bool isSpecialChar(char32_t _val); /** - * @brief check if the curent element is number or not - * @return tue if it is a number char + * @brief check if the curent element is number or not [0-9] + * @param[in] _val Value to interprete + * @return true if it is a number char + * @return false otherwise */ bool isInteger(char32_t _val); + /** + * @brief Convert char32_t in an interfer + * @param[in] _val Value to interprete + * @return The parsed Value or ... + */ int32_t toInt(char32_t _val); - + /** + * @brief Change order of the value to have an order of display with A->Z and after a->z and after 0->9 and after all the rest .... + * @param[in] _val Value in unicode + * @return A value usable in interfer only ... to check order... + */ char32_t changeOrder(char32_t _val); + /** + * @brief Conver unicode in UTF8 value + * @param[in] _val Value to convert + * @param[out] _output Char data converted + * @return Number of char in utf8 + */ int8_t convertUtf8(char32_t _val, char _output[5]); #if __CPP_VERSION__ >= 2011 std::string convertToUtf8(const std::u32string& _input); #endif }; +/** + * @brief UTF-8 simple wrapper interface + */ namespace utf8 { /** * @brief Get the size of an utf8 char with his first char. @@ -58,7 +89,11 @@ namespace utf8 { * @return true if it was the first char. */ bool theoricFirst(const char _input); - + /** + * @brief Convert a char* in a unicode value + * @param[in] _input pointer on a string C (utf-8) to convert + * @return Converted Value + */ char32_t convertChar32(const char* _input); #if __CPP_VERSION__ >= 2011 std::u32string convertUnicode(const std::string& _input); @@ -402,41 +437,61 @@ namespace utf8 { namespace std { #if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__Windows)) - typedef std::basic_string u32string; + using u32string = std::basic_string; #endif #if (defined(__TARGET_OS__Android)) - //! @previous + //! @not_in_doc std::string to_string(int _val); - //! @previous + //! @not_in_doc std::string to_string(long _val); - //! @previous + //! @not_in_doc std::string to_string(long long _val); - //! @previous + //! @not_in_doc std::string to_string(unsigned _val); - //! @previous + //! @not_in_doc std::string to_string(unsigned long _val); - //! @previous + //! @not_in_doc std::string to_string(unsigned long long _val); - //! @previous + //! @not_in_doc std::string to_string(float _val); - //! @previous + //! @not_in_doc std::string to_string(double _val); - //! @previous + //! @not_in_doc std::string to_string(long double _val); + //! @not_in_doc double stod(const std::string& _str, size_t* _idx = 0); + //! @not_in_doc float stof(const std::string& _str, size_t* _idx = 0); + //! @not_in_doc int stoi(const std::string& _str, size_t* _idx = 0, int _base = 10); + //! @not_in_doc long stol(const std::string& _str, size_t* _idx = 0, int _base = 10); + //! @not_in_doc long double stold(const std::string& _str, size_t* _idx = 0); + //! @not_in_doc long long stoll(const std::string& _str, size_t* _idx = 0, int _base = 10); + //! @not_in_doc unsigned long stoul(const std::string& _str, size_t* _idx = 0, int _base = 10); + //! @not_in_doc unsigned long long stoull(const std::string& _str, size_t* _idx = 0, int _base = 10); #endif }; namespace etk { // these declaration is to prevent some under template declaration of unknown type - template std::string to_string(const TYPE& _variable); - template std::string to_string(const std::vector& _list) { + /** + * @brief Template to declare convertion from anything in std::string + * @param[in] _variable Variable to convert + * @return String of the value + */ + template + std::string to_string(const TYPE& _variable); + /** + * @brief Template to declare convertion from std::vector in std::string + * @param[in] _list Variable to convert + * @return String of the value: {...,...,...} + */ + template + std::string to_string(const std::vector& _list) { std::string out = "{"; for (size_t iii=0; iii<_list.size(); ++iii) { if (iii!=0) { @@ -448,131 +503,142 @@ namespace etk { return out; } #if __CPP_VERSION__ >= 2011 - template std::u32string to_u32string(const TYPE& _variable); + template + std::u32string to_u32string(const TYPE& _variable); #endif // these declaration is to prevent some under template declaration of unknown type - template bool from_string(TYPE& _variableRet, const std::string& _value); + /** + * @brief Template to declare convertion from string to anything + * @param[out] _variableRet Output value + * @param[in] _value input property + * @return true if the can be converted. + */ + template + bool from_string(TYPE& _variableRet, const std::string& _value); #if __CPP_VERSION__ >= 2011 - template bool from_string(TYPE& _variableRet, const std::u32string& _value); + template + bool from_string(TYPE& _variableRet, const std::u32string& _value); #endif // TODO : Change this in : // TODO : template TYPE string_to(const std::u32string& _value); ==> check exceptions ... + //! @not_in_doc long double string_to_long_double(const std::string& _str); #if __CPP_VERSION__ >= 2011 long double string_to_long_double(const std::u32string& _str); #endif - + //! @not_in_doc double string_to_double(const std::string& _str); #if __CPP_VERSION__ >= 2011 double string_to_double(const std::u32string& _str); #endif - + //! @not_in_doc float string_to_float(const std::string& _str); #if __CPP_VERSION__ >= 2011 float string_to_float(const std::u32string& _str); #endif - + //! @not_in_doc int8_t string_to_int8_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 int8_t string_to_int8_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc int16_t string_to_int16_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 int16_t string_to_int16_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc int32_t string_to_int32_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 int32_t string_to_int32_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc int64_t string_to_int64_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 int64_t string_to_int64_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc uint8_t string_to_uint8_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 uint8_t string_to_uint8_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc uint16_t string_to_uint16_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 uint16_t string_to_uint16_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc uint32_t string_to_uint32_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 uint32_t string_to_uint32_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc uint64_t string_to_uint64_t(const std::string& _str, int _base = 10); #if __CPP_VERSION__ >= 2011 uint64_t string_to_uint64_t(const std::u32string& _str, int _base = 10); #endif - + //! @not_in_doc bool string_to_bool(const std::string& _str); #if __CPP_VERSION__ >= 2011 bool string_to_bool(const std::u32string& _str); #endif - + //! @not_in_doc std::string tolower(std::string _obj); #if __CPP_VERSION__ >= 2011 //! @previous std::u32string tolower(std::u32string _obj); #endif - + //! @not_in_doc std::string toupper(std::string _obj); #if __CPP_VERSION__ >= 2011 //! @previous std::u32string toupper(std::u32string _obj); #endif - + //! @not_in_doc bool compare_no_case(const std::string& _obj, const std::string& _val); #if __CPP_VERSION__ >= 2011 //! @previous bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); #endif - + //! @not_in_doc bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true); #if __CPP_VERSION__ >= 2011 //! @previous bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); #endif - + //! @not_in_doc bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true); #if __CPP_VERSION__ >= 2011 //! @previous bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true); #endif - + //! @not_in_doc std::string replace(const std::string& _obj, char _val, char _replace); #if __CPP_VERSION__ >= 2011 //! @previous std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace); #endif - + //! @not_in_doc std::string extract_line(const std::string& _obj, int32_t _pos); #if __CPP_VERSION__ >= 2011 //! @previous std::u32string extract_line(const std::u32string& _obj, int32_t _pos); #endif - + //! @not_in_doc std::vector split(const std::string& _input, char _val); #if __CPP_VERSION__ >= 2011 //! @previous std::vector split(const std::u32string& _input, char32_t _val); #endif - + //! @not_in_doc void sort(std::vector& _list); #if __CPP_VERSION__ >= 2011 //! @previous void sort(std::vector& _list); #endif - - template bool isIn(const T& _val, const std::vector& _list) { + //! @not_in_doc + template + bool isIn(const T& _val, const std::vector& _list) { for (size_t iii=0; iii<_list.size(); ++iii) { if (_list[iii] == _val) { return true; @@ -583,8 +649,15 @@ namespace etk { }; namespace std { - template const TYPE& avg(const TYPE& a, const TYPE& b, const TYPE& c) { - return std::min(std::max(a,b),c); + /** + * @brief in std, we have min, max but not avg ==> it is missing... the Defineing avg template. + * @param[in] _min Minimum value of the range + * @param[in] _val The value that we want a min/max + * @param[in] _max Maximum value of the range + * @return Value that min/max applied + */ + template const TYPE& avg(const TYPE& _min, const TYPE& _val, const TYPE& _max) { + return std::min(std::max(_min,_val),_max); } }; @@ -623,10 +696,14 @@ namespace std { std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj); //! @not_in_doc std::ostream& operator <<(std::ostream& _os, const std::chrono::steady_clock::time_point& _obj); - -}; +} -int32_t strlen(const char32_t * _data); +/** + * @brief Claculate the size of a string (unicode) + * @param[in] _data Data to parse to find the end of string + * @return the Number of char32_t befor the '\\0' value + */ +int32_t strlen(const char32_t* _data); #if (defined(__TARGET_OS__Windows)) #define M_PI 3.14159265358979323846 diff --git a/etk/tool.h b/etk/tool.h index d49a2b8..a676b68 100644 --- a/etk/tool.h +++ b/etk/tool.h @@ -11,15 +11,24 @@ #pragma once namespace etk { + /** + * @brief Some un-usefull tools + * @todo Remove all of this use std11 random + */ namespace tool { /** - * @brief Get a random value in a specific range. + * @brief Get a random value in a specific range in float. * @param[in] _a Lower value of the random. * @param[in] _b Bigger value of the random. * @return Random Value between [_a and _b] */ double frand(double _a, double _b); - //! @previous + /** + * @brief Get a random value in a specific range in integer. + * @param[in] _a Lower value of the random. + * @param[in] _b Bigger value of the random. + * @return Random Value between [_a and _b] + */ int32_t irand(int32_t _a, int32_t _b); /** * @brief Reset the random system with a random value (time). diff --git a/etk/types.h b/etk/types.h index aa9e986..16b3a6a 100644 --- a/etk/types.h +++ b/etk/types.h @@ -44,13 +44,15 @@ #include #ifndef ETK_BUILD_LINEARMATH - typedef float btScalar; + //! @brief If not using linear math from bullet lib, we need to define the basic element of a btScalar (float) + using btScalar = float; #endif #ifndef _WIN32 #include #ifndef _MATH_H_MATHDEF - typedef float float_t; + //! @not_in_doc + using float_t = float; #endif #endif diff --git a/test/main.cpp b/test/main.cpp index 0a1d87f..3239715 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -26,10 +26,6 @@ #include "testHash.hpp" #include "testStdShared.hpp" -#undef __class__ -#define __class__ "etktest" - - int main(int argc, const char *argv[]) { // init Google test : ::testing::InitGoogleTest(&argc, const_cast(argv)); diff --git a/test/testArchive.hpp b/test/testArchive.hpp index 4db2898..704e4ac 100644 --- a/test/testArchive.hpp +++ b/test/testArchive.hpp @@ -10,9 +10,6 @@ #undef NAME #define NAME "Archive" -#undef __class__ -#define __class__ "etktest" - #ifdef ETK_BUILD_MINIZIP TEST(TestEtkArchive, CreationWrong) { diff --git a/test/testColor.hpp b/test/testColor.hpp index 5c111a0..5b954fb 100644 --- a/test/testColor.hpp +++ b/test/testColor.hpp @@ -10,9 +10,6 @@ #undef NAME #define NAME "Color" -#undef __class__ -#define __class__ "etktest" - TEST(TestEtkColor, RGBA8) { etk::Color colorRGBA8(0x52,0x0F, 0x65, 0x44); EXPECT_EQ(colorRGBA8.r(), 0x52); diff --git a/test/testFSNode.hpp b/test/testFSNode.hpp index 3165e95..756e5d6 100644 --- a/test/testFSNode.hpp +++ b/test/testFSNode.hpp @@ -10,9 +10,6 @@ #undef NAME #define NAME "FSNode" -#undef __class__ -#define __class__ "etktest" - TEST(TestEtkFSNode, checkType) { std::string fileName("USERDATA:myFileTest.txt"); etk::FSNode myNodeTest1(fileName); diff --git a/test/testHash.hpp b/test/testHash.hpp index fc6e7c5..f8250ec 100644 --- a/test/testHash.hpp +++ b/test/testHash.hpp @@ -11,9 +11,6 @@ #undef NAME #define NAME "Hash" -#undef __class__ -#define __class__ "etktest" - TEST(TestEtkHash, Creation) { etk::Hash testData; EXPECT_EQ(testData.size(), 0); diff --git a/test/testStdShared.hpp b/test/testStdShared.hpp index 6851535..45a551e 100644 --- a/test/testStdShared.hpp +++ b/test/testStdShared.hpp @@ -11,9 +11,6 @@ #undef NAME #define NAME "Shared_ptr" -#undef __class__ -#define __class__ "etktest" - class Example : public std::enable_shared_from_this { protected: int32_t m_id;