diff --git a/debug_cli/DbgCliNode.h b/debug_cli/DbgCliNode.h index e11c0c8..1ec5801 100644 --- a/debug_cli/DbgCliNode.h +++ b/debug_cli/DbgCliNode.h @@ -8,6 +8,9 @@ #ifndef PLAT_DEBUG_CLI_DBGCLINODE_H_ #define PLAT_DEBUG_CLI_DBGCLINODE_H_ +/** + * Composite Pattern: Abstract Node Class, acts as the Interface to the object tree. + */ class DbgCli_Node { protected: // abstract class - constructor must not be accessible diff --git a/debug_cli/DbgCliTopic.cpp b/debug_cli/DbgCliTopic.cpp index f652e31..8ebf20a 100644 --- a/debug_cli/DbgCliTopic.cpp +++ b/debug_cli/DbgCliTopic.cpp @@ -19,6 +19,8 @@ DbgCli_Topic* DbgCli_Topic::RootNode() DbgCli_Topic::DbgCli_Topic(const char* parentPath, const char* nodeName, const char* helpText) : DbgCli_Node(parentPath, nodeName, helpText) +, m_child(0) +, m_sibling(0) { } DbgCli_Topic::~DbgCli_Topic() @@ -27,6 +29,8 @@ DbgCli_Topic::~DbgCli_Topic() void DbgCli_Topic::addNode(DbgCli_Node* node) { // TODO: search the parent node according to the provided parentPath given by the node object. + const char* parentPath = node->getParentPath(); + } DbgCli_Node* DbgCli_Topic::getNode(const char* cmdPath, unsigned int cmdPathStrLen) @@ -40,3 +44,14 @@ void DbgCli_Topic::execute(unsigned int arg_cnt, char* args[], unsigned int idxT // TODO: Finds its path according to the args array's tokens. // TODO: Calls the execute method of the right child node if found, increments the index to the first parameter to handle accordingly. } + +void DbgCli_Topic::addChildNode(DbgCli_Node* node) +{ + DbgCli_Topic* tmpTopic = m_child; + while (0 != tmpTopic) + { + tmpTopic = tmpTopic->m_sibling; + } + tmpTopic->addNode(node); +} + diff --git a/debug_cli/DbgCliTopic.h b/debug_cli/DbgCliTopic.h index de51598..aa3ca61 100644 --- a/debug_cli/DbgCliTopic.h +++ b/debug_cli/DbgCliTopic.h @@ -11,7 +11,7 @@ #include /** - * This is the Compositum part of the Composite Pattern. + * This is the Composite part of the Composite Pattern. */ class DbgCli_Topic: public DbgCli_Node { @@ -44,9 +44,15 @@ class DbgCli_Topic: public DbgCli_Node */ virtual void execute(unsigned int argc, char* args[], unsigned int idxToFirstArgToHandle); +private: + void addChildNode(DbgCli_Node* node); + DbgCli_Node* getChildNode(const char* childNodeName); + private: static DbgCli_Topic* s_rootNode; + DbgCli_Node* m_child; + DbgCli_Node* m_sibling; private: // forbidden default functions DbgCli_Topic& operator= (const DbgCli_Topic& src); // assignment operator