diff --git a/aidge/_Core/include/nodeTester/ConditionalData.hpp b/aidge/_Core/include/nodeTester/ConditionalData.hpp index 7477cae9fdc9a645f928c258a807fbb60fc053fa..61c04e5b8bc04b23f0ed6d52eae554c3c823147a 100644 --- a/aidge/_Core/include/nodeTester/ConditionalData.hpp +++ b/aidge/_Core/include/nodeTester/ConditionalData.hpp @@ -83,17 +83,17 @@ struct ConditionalData { */ template <typename T> void setValue(const T& newValue) { - // if (std::is_pointer<T>::value) { - // throw std::runtime_error("Pointer type not allowed."); - // } - deleteValue(); //the old one - //value = new Value<T>(newValue); + //make sure that the old value is free + deleteValue(); value = std::make_unique<ConditionalValue<T>>(newValue); type = &typeid(T); } /** - * @brief set a value for vetor + * @brief get the actual value + * @details recaste the value to the templaited type and checks that the conversion type is compatible with type + * @tparam the type of the return value + * @return the value */ template <typename T> T getValue() const { diff --git a/aidge/_Core/include/nodeTester/ConditionalInterpreter.hpp b/aidge/_Core/include/nodeTester/ConditionalInterpreter.hpp index eb685f885ff8e51c8248992a4e084d5dd65cf96e..5d8d46c6bdb9fef0432a019cefc5102169b58227 100644 --- a/aidge/_Core/include/nodeTester/ConditionalInterpreter.hpp +++ b/aidge/_Core/include/nodeTester/ConditionalInterpreter.hpp @@ -20,13 +20,21 @@ namespace Aidge{ ////////////////////////////// // ///////////////////////////// - +/** + * @brief class used to register any lambda function without context, + * it encapsulates the source lambda in a lambda which takes as argument ConditionalData* which are any type. + * @see ConditionalData + */ class ConditionalRegisterFunction { ////////////////////////// //Safe recaste ////////////////////////// - - + + /** + * @brief recaste the ConditionalData* to the argument type of the lambda + * @tparam T type of the lambda argument + * @see ConditionalData + */ template <typename T> T safeCastInput(ConditionalData* data) { //cnvertion and type cheking @@ -39,7 +47,11 @@ class ConditionalRegisterFunction { } - //convert the output of f to a ConditionalData* + /** + * @brief recaste the output of the lambda to a ConditionalData* + * @tparam T type of the lambda return + * @see ConditionalData + */ template <typename T> ConditionalData* safeCastOutput(T data) { @@ -129,7 +141,7 @@ class ConditionalRegisterFunction { }; } - /** + /** * @brief Converts a function pointer to a ConditionalData*(std::vector<ConditionalData*>). * @tparam R The return type of the function. * @tparam Params The parameter types of the function. @@ -141,6 +153,13 @@ class ConditionalRegisterFunction { return funcPointer(f, std::index_sequence_for<Params...>{}); } + /** + * @brief Converts a std::function to a ConditionalData*(std::vector<ConditionalData*>). + * @tparam R The return type of the function. + * @tparam Params The parameter types of the function. + * @param f The function pointer to convert. + * @return The pointer to the converted function. + */ template <class R,class... Params> auto funcPointer(std::function<R(Params...)> f) { return funcPointer(f, std::index_sequence_for<Params...>{}); @@ -187,12 +206,27 @@ class ConditionalRegisterFunction { /////////////////// //AST tree node // //////////////// +/** + * @brief this class interprets AST to generate a test on a graph node. For each AST node, + * it generates an interpretation and registers lambda functions that can be used in the test expression. + * there are two lambda control mechanisms: + * - A cpp mechanism which allows any lambda to be inserted into the constructor that use templaite + * - A user mechanism limited to lambda bool(NodePtr) + * @see ConditionalParser use to get the AST + */ class ConditionalInterpreter { private: - + /** + * @brief the AST generate by the Parser + * @see ConditionalParser + */ std::shared_ptr<Aidge::AstConditionalNode> mTree; + /** + * @brief the registery for the lambda fuction + * @see ConditionalRegisterFunction + */ ConditionalRegisterFunction mLambdaRegiter; public: @@ -206,13 +240,16 @@ class ConditionalInterpreter /** * @brief Test a node depending of the ConditionalExpressions - * @return bool + * @details the AST is visit using \ref visit() whith the $ init whit the nodeOp + * @return bool the match node has the initialized expresion + * @see visit() This function uses the visit() function to perform the evaluation. */ bool test( const NodePtr nodeOp); /** - * @brief Interface for inserting custom lambda bool(NodePtr) functions in AST interpretation - * @param key The key that will be used to call the function in the expression + * @brief Interface for inserting custom lambda bool(NodePtr) functions in AST interpretation, + * it will be available in the ConditionalExpressions expretion as : key($) + * @param key The key that will be used to call the function in the expression * @param f The pointer to function */ void insertLambda(const std::string key,std::function<bool(Aidge::NodePtr)> f); @@ -220,7 +257,6 @@ class ConditionalInterpreter ///// - private: /** * @brief Recursive AST traversal function, using the for interpreting AST nodes function, diff --git a/aidge/_Core/include/nodeTester/ConditionalLexer.hpp b/aidge/_Core/include/nodeTester/ConditionalLexer.hpp index 5e0cb0f77d3394cd8d2e23fb71d39cedd2c0f178..f21e0f15edd6451fc51fab690aa85fa7746ff91f 100644 --- a/aidge/_Core/include/nodeTester/ConditionalLexer.hpp +++ b/aidge/_Core/include/nodeTester/ConditionalLexer.hpp @@ -26,37 +26,41 @@ namespace Aidge{ /** + * @brief enum for all types of token use in the parsing * 7-5 type * 4-0 id */ enum class ConditionalTokenTypes { - NOT = (1 << 4)+3, - AND = (1 << 4)+2, - OR = (1 << 4)+1, - - EQ = (1 << 5)+1, - NEQ = (1 << 5)+2, - - KEY = (1 << 6) +1 , - INTEGER = (1 << 6) +2 , - FLOAT = (1 << 6) +3 , - STRING = (1 << 6) +4 , - BOOL = (1 << 6) +5 , - NODE = (1 << 6) +6 , //the node ptr - LAMBDA = (1 << 6) +7 , //the fuction TAG - - ARGSEP = (1<<7) +1,//sep fuction , - LPAREN = (1<<7) +2, - RPAREN = (1<<7) +3, - STOP = 0, + NOT = (1 << 4)+3, /**< ! */ + AND = (1 << 4)+2, /**< && */ + OR = (1 << 4)+1, /**< || */ + + EQ = (1 << 5)+1, /**< == */ + NEQ = (1 << 5)+2, /**< != */ + + KEY = (1 << 6) +1 , /**< [A-Za-z][A-Za-z0-9_]* */ + INTEGER = (1 << 6) +2 , /**< [0-9]+ */ + FLOAT = (1 << 6) +3 , /**< [0-9]+\.[0-9]* */ + STRING = (1 << 6) +4 , /**< \'.*\' */ + BOOL = (1 << 6) +5 , /**< true|false */ + NODE = (1 << 6) +6 , /**< \$ */ + LAMBDA = (1 << 6) +7 , /**< [A-Za-z][A-Za-z0-9_]*\( */ + + ARGSEP = (1<<7) +1, /**< , */ + LPAREN = (1<<7) +2, /**< \( */ + RPAREN = (1<<7) +3, /**< \) */ + STOP = 0, }; -class ConditionalToken -{ + + /** * @brief token holder */ +class ConditionalToken +{ + public: /** @@ -67,7 +71,6 @@ public: ConditionalToken(const ConditionalTokenTypes type , const std::string lexeme ); /** * @brief get the lexeme - * * @return std::string */ const std::string getLexeme(void); @@ -79,14 +82,25 @@ const std::string getLexeme(void); */ const ConditionalTokenTypes getType(void); - +/** + * @brief copy the token + * @return deep copy of the token + */ std::shared_ptr<Aidge::ConditionalToken> copy(); std::ostringstream rep(void); private: +/** + * @brief additional information of the token + */ const std::string mLexeme; + +/** + * @brief type of the token + * @see ConditionalTokenTypes + */ const ConditionalTokenTypes mType; }; @@ -101,7 +115,6 @@ ConditionalLexer( const std::string ConditionalExpressions ); /** * @brief Get the next token on the ConditionalExpressions - * * @return ConditionalToken */ std::shared_ptr<ConditionalToken> getNextToken(void); diff --git a/aidge/_Core/include/nodeTester/ConditionalParser.hpp b/aidge/_Core/include/nodeTester/ConditionalParser.hpp index c744b1b577fa5ab978bb6c4b8539fdfe4116d548..381f207af07131586b45965115002094c638e514 100644 --- a/aidge/_Core/include/nodeTester/ConditionalParser.hpp +++ b/aidge/_Core/include/nodeTester/ConditionalParser.hpp @@ -18,22 +18,54 @@ const std::map<ConditionalTokenTypes, std::size_t> ConditionalPrec{ class AstConditionalNode; // Forward declaration using ASTNodeCh = std::vector<std::shared_ptr<AstConditionalNode>>; +/** + * @brief this class is the node of an AST tree, this + */ class AstConditionalNode: public std::enable_shared_from_this<AstConditionalNode> { public: AstConditionalNode(std::shared_ptr<ConditionalToken> token,ASTNodeCh child ={}); - + /** + * @brief get the lexeme of the token + * @return the lexeme value + */ std::string getValue() const; + /** + * @brief get the type of the token + * @return the type + */ ConditionalTokenTypes getType() const; + std::string getValue() const; + /** + * @brief get the child of the node + * @return child + */ const ASTNodeCh& getChilds() const ; + /** + * @brief test if the node is a leaf in the tree + * @return true if a leaf + */ bool isLeaf() const ; + + /** + * @brief get the number of child + * @return the number of child + */ std::size_t nbChild() const; private: + /** + * @brief the token of the node + */ const std::shared_ptr<ConditionalToken> mToken; + /** + * @brief list of child + */ const ASTNodeCh mChild; }; - +/** + * @brief this class uses the lexer to create an AST according to a set of gramer rules + */ class ConditionalParser{ public: @@ -53,12 +85,9 @@ class ConditionalParser{ private: /** * @brief restart at the start of the ConditionalExpressions for LEXER and restart mCurrentToken - * */ void rstParser(void); - - - + ////////////////// /**