2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 // @ Project : Access Control Engine
20 // @ File Name : TreeNode.h
21 // @ Date : 2009-05-06
32 #include <ace/AbstractTreeElement.h>
36 typedef std::list<TreeNode *> ChildrenSet;
37 typedef std::list<TreeNode *>::iterator ChildrenIterator;
38 typedef std::list<TreeNode *>::const_iterator ChildrenConstIterator;
43 //TODO nazwac pozadnie TYPY - moze jakas konwencja ... ??!!
44 enum TypeID { Policy =0, PolicySet=1, Rule=2};
46 const ChildrenSet & getChildrenSet() const
51 TreeNode * getParent() const
56 void setParent(TreeNode *parent)
58 this->parent = parent;
61 TypeID getTypeID() const
66 void addChild(TreeNode *child)
68 child->setParent(this);
69 children.push_back(child);
75 // KW TreeNode * clone() { return new TreeNode(NULL,this->getTypeID(),this->getElement()); }
77 TreeNode(TreeNode * parent,
79 AbstractTreeElement * element) :
86 AbstractTreeElement * getElement() const
96 * It is common that we create a copy of tree structure created out of xml file. However we don't want to
97 * copy abstract elements ( Policies and Rules ) because we need them only for reading. We want to modify the
98 * tree structure though. Therefore we copy TreeNode. When the copy of the original tree is being destroyed method
99 * releaseTheSubtree should be called on "root". It automatically traverse the tree and call TreeNode destructors for
100 * each TreeNode in the tree. It doesn't remove the abstract elements in the tree ( there is always at most one abstract
101 * element instance, when tree is copied it is a shallow copy.
102 * When we want to completely get rid of the the tree and abstract elements we have to call releaseResources on tree root.
103 * We may want to do this for instance when we want to serialize the tree to disc. releaseResource method traverses the tree
104 * and releses the resources, as well as the TreeNode so NO releaseTheSubtree is required any more
106 void releaseResources();
109 * Used to delete the copies of tree structure. The original tree structure should be removed with releaseResources method.
110 * ReleaseTheSubtree method doesn't delete the abstract elements, only TreeNodes. It traverses the whole tree, so it should be
111 * called on behalf of root of the tree
113 // KW void releaseTheSubtree();
115 friend std::ostream & operator<<(std::ostream & out,
116 const TreeNode * node);
117 // KW void printSubtree();
120 // KW TreeNode(const TreeNode& pattern){ (void)pattern; }
122 std::list<TreeNode *> children;
124 //TODO standarize ID case
126 AbstractTreeElement * element;
130 #endif //_TREE_NODE_H