1 /*****************************************************************************
2  *
3  * Copyright (c) 2008-2010, CoreCodec, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of CoreCodec, Inc. nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  ****************************************************************************/
29 
30 #ifndef __NODETREE_H
31 #define __NODETREE_H
32 
33 #define NODETREE_CLASS		FOURCC('T','R','E','E')
34 
35 #define NODETREE_PARENT     20
36 #define NODETREE_NEXT       21
37 
38 typedef struct nodetree nodetree;
39 
40 typedef struct nodetree_vmt
41 {
42     node_vmt Base;
43 
44     err_t (*SetParent)(thisnode,void* Parent,void* Before);
45     err_t (*AddChild)(thisnode,void* Child,void* Before); //private
46     void (*RemoveChild)(thisnode,void* Child); //private
47     nodetree* (*AddData)(thisnode,const tchar_t* Name,dataflags Flags);
48     nodetree* (*FindChild)(thisnode,const tchar_t* Name);
49 
50 } nodetree_vmt;
51 
52 struct nodetree
53 {
54     node Base;
55 	nodetree* Parent;
56 	nodetree* Next;
57 	nodetree* Children;
58 };
59 
60 #define NodeTree_SetParent(p,a,b) VMT_FUNC(p,nodetree_vmt)->SetParent(p,a,b)
61 #define NodeTree_AddData(p,a,b)   VMT_FUNC(p,nodetree_vmt)->AddData(p,a,b)
62 #define NodeTree_FindChild(p,a)   VMT_FUNC(p,nodetree_vmt)->FindChild(p,a)
63 #define NodeTree_Parent(p)        ((nodetree*)(p))->Parent
64 #define NodeTree_Children(p)      ((nodetree*)(p))->Children
65 #if defined(NDEBUG)
66 #define NodeTree_Next(p)          ((nodetree*)(p))->Next
67 #else
68 #define NodeTree_Next(p)          (assert((nodetree*)(p) != ((nodetree*)(p))->Next),((nodetree*)(p))->Next)
69 #endif
70 
71 NODE_DLL nodetree* NodeTree_CreateChild(void* p, const tchar_t* Name, fourcc_t ClassId, void* Before);
72 NODE_DLL nodetree* NodeTree_ChildByName(const void* p,const tchar_t* Name, fourcc_t Class, bool_t Recursive);
73 NODE_DLL nodetree* NodeTree_ChildByClass(const void* p,fourcc_t Class);
74 NODE_DLL nodetree* NodeTree_DetachAndRelease(void* p);
75 NODE_DLL void NodeTree_MoveBefore(void* p, void* Before);
76 NODE_DLL void NodeTree_Clear(nodetree* p);
77 
78 #endif
79