Debian Codegraph @

CodeLite/tag_tree.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2008 by Eran Ifrah
5 // file name : tag_tree.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25 #include "precompiled_header.h"
26
27 #include "tag_tree.h"
28 #include "tokenizer.h"
29 #ifdef __VISUALC__
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #endif
33 #endif
34
35
36 TagTree::TagTree(const wxString& key, const TagEntry& data)
37 : Tree<wxString, TagEntry>(key, data)
38 {
39 }
40
41 TagTree::~TagTree()
42 {
43 }
44
45 /// Util function to help us to build a tree from tags
46 TagNode* TagTree::AddEntry(TagEntry& tag)
47 {
48 // If a node with thig tag already exist, we simply updating the
49 // data
50 wxString key(tag.Key());
51
52 TagNode* newNode = Find(key);
53 if( newNode )
54 {
55 if( tag.IsOk() )
56 newNode->SetData(tag);
57 return newNode;
58
59 }
60
61 // To add an entry to the tree, we first must make sure
62 // that all path to it exist
63 wxString name = tag.GetPath();
64 StringTokenizer tok(name, wxT("::"));
65
66 wxString parentPath;
67 TagNode* node = GetRoot();
68 TagNode* lastFoundNode = GetRoot();
69 for(int i=0; i<tok.Count()-1; i++)
70 {
71 parentPath += tok[i];
72
73 // Try to find this node in the tree
74 node = Find(parentPath);
75 if( !node )
76 {
77 // Node does not exist add it, we copy key values
78 // from 'tag'
79 TagEntry ee;
80 ee.SetPath(parentPath);
81 ee.SetName(tok[i]);
82 node = AddChild(parentPath, ee, lastFoundNode);
83 }
84
85 lastFoundNode = node;
86 if(i < tok.Count()-2)
87 parentPath += _T("::");
88 }
89
90 return AddChild(key, tag, node);
91 }
92