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 <dpl/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 virtual bool serialize(std::ostream& os);
48 TreeNode(std::istream& is,
51 const ChildrenSet & getChildrenSet() const
56 TreeNode * getParent() const
61 void setParent(TreeNode *parent)
63 this->parent = parent;
66 TypeID getTypeID() const
71 void addChild(TreeNode *child)
73 child->setParent(this);
74 children.push_back(child);
80 // KW TreeNode * clone() { return new TreeNode(NULL,this->getTypeID(),this->getElement()); }
82 TreeNode(TreeNode * parent,
84 AbstractTreeElement * element) :
91 AbstractTreeElement * getElement() const
101 * It is common that we create a copy of tree structure created out of xml file. However we don't want to
102 * copy abstract elements ( Policies and Rules ) because we need them only for reading. We want to modify the
103 * tree structure though. Therefore we copy TreeNode. When the copy of the original tree is being destroyed method
104 * releaseTheSubtree should be called on "root". It automatically traverse the tree and call TreeNode destructors for
105 * each TreeNode in the tree. It doesn't remove the abstract elements in the tree ( there is always at most one abstract
106 * element instance, when tree is copied it is a shallow copy.
107 * When we want to completely get rid of the the tree and abstract elements we have to call releaseResources on tree root.
108 * We may want to do this for instance when we want to serialize the tree to disc. releaseResource method traverses the tree
109 * and releses the resources, as well as the TreeNode so NO releaseTheSubtree is required any more
111 void releaseResources();
114 * Used to delete the copies of tree structure. The original tree structure should be removed with releaseResources method.
115 * ReleaseTheSubtree method doesn't delete the abstract elements, only TreeNodes. It traverses the whole tree, so it should be
116 * called on behalf of root of the tree
118 // KW void releaseTheSubtree();
120 friend std::ostream & operator<<(std::ostream & out,
121 const TreeNode * node);
122 // KW void printSubtree();
125 // KW TreeNode(const TreeNode& pattern){ (void)pattern; }
127 std::list<TreeNode *> children;
129 //TODO standarize ID case
131 AbstractTreeElement * element;
135 #endif //_TREE_NODE_H