Debian Codegraph @

CodeLite/PHPEntityBase.cpp

raw
1 #include "PHPEntityBase.h"
2 #include <algorithm>
3
4 PHPEntityBase::PHPEntityBase()
5 : m_parent(NULL)
6 , m_line(0)
7 , m_column(0)
8 , m_flags(0)
9 , m_dbId(wxNOT_FOUND)
10 {
11 }
12
13 void PHPEntityBase::AddChild(PHPEntityBase::Ptr_t child)
14 {
15 // Add the child to this entity
16 if(m_childrenMap.count(child->GetFullName()) == 0) {
17 m_children.push_back(child);
18 m_childrenMap.insert(std::make_pair(child->GetFullName(), child));
19 child->m_parent = this;
20 }
21 }
22
23 void PHPEntityBase::RecursivePrintStdout(PHPEntityBase::Ptr_t parent, int indent) { PrintStdout(indent); }
24
25 PHPEntityBase::Ptr_t PHPEntityBase::FindChild(const wxString& name, bool tryPrependingDollar) const
26 {
27 PHPEntityBase::Map_t::const_iterator iter = m_childrenMap.find(name);
28 if(iter != m_childrenMap.end()) {
29 return iter->second;
30 }
31
32 // Could not find an exact match, try prepending
33 if(tryPrependingDollar) {
34 wxString modName = name;
35 if(!modName.StartsWith("$")) {
36 modName.Prepend("$");
37 }
38 iter = m_childrenMap.find(modName);
39 if(iter != m_childrenMap.end()) {
40 return iter->second;
41 }
42 }
43 return PHPEntityBase::Ptr_t(NULL);
44 }
45
46 void PHPEntityBase::StoreRecursive(PHPLookupTable* lookup)
47 {
48 Store(lookup);
49
50 // save the children
51 PHPEntityBase::List_t::iterator iter = m_children.begin();
52 for(; iter != m_children.end(); ++iter) {
53 (*iter)->StoreRecursive(lookup);
54 }
55 }
56
57 void PHPEntityBase::SetChildren(const PHPEntityBase::List_t& children)
58 {
59 m_children.clear();
60 m_childrenMap.clear();
61 PHPEntityBase::List_t::const_iterator iter = children.begin();
62 for(; iter != children.end(); ++iter) {
63 AddChild(*iter);
64 }
65 }
66
67 void PHPEntityBase::SetFullName(const wxString& fullname)
68 {
69 m_fullname = fullname;
70 m_shortName = m_fullname.AfterLast('\\');
71 }
72
73 void PHPEntityBase::RemoveChild(PHPEntityBase::Ptr_t child)
74 {
75 // Remove the child from the map
76 if(m_childrenMap.count(child->GetFullName())) {
77 m_childrenMap.erase(child->GetFullName());
78 }
79
80 // Remove the child from the list as well
81 PHPEntityBase::List_t::iterator iter =
82 std::find_if(m_children.begin(), m_children.end(), [&](PHPEntityBase::Ptr_t c) {
83 if(c->GetFullName() == child->GetFullName()) {
84 return true;
85 }
86 return false;
87 });
88
89 if(iter != m_children.end()) {
90 m_children.erase(iter);
91 }
92 child->m_parent = NULL;
93 }
94
95 JSONItem PHPEntityBase::BaseToJSON(const wxString& entityType) const
96 {
97 JSONItem json = JSONItem::createObject();
98 json.addProperty("type", entityType);
99 json.addProperty("file", m_filename.GetFullPath());
100 json.addProperty("name", m_shortName);
101 json.addProperty("fullname", m_fullname);
102 json.addProperty("doc", m_docComment);
103 json.addProperty("line", m_line);
104 json.addProperty("col", m_column);
105 json.addProperty("flags", m_flags);
106 return json;
107 }
108
109 void PHPEntityBase::BaseFromJSON(const JSONItem& json)
110 {
111 m_filename = json.namedObject("file").toString();
112 m_shortName = json.namedObject("name").toString();
113 m_fullname = json.namedObject("fullname").toString();
114 m_docComment = json.namedObject("doc").toString();
115 m_line = json.namedObject("line").toInt(0);
116 m_column = json.namedObject("col").toInt(0);
117 m_flags = json.namedObject("flags").toSize_t(0);
118 }