File: PHPEntityBase.cpp

package info (click to toggle)
codelite 10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 71,364 kB
  • sloc: cpp: 415,397; ansic: 18,277; php: 9,547; lex: 4,181; yacc: 2,820; python: 2,294; sh: 383; makefile: 51; xml: 13
file content (92 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "PHPEntityBase.h"
#include <algorithm>

PHPEntityBase::PHPEntityBase()
    : m_parent(NULL)
    , m_line(0)
    , m_column(0)
    , m_flags(0)
    , m_dbId(wxNOT_FOUND)
{
}

void PHPEntityBase::AddChild(PHPEntityBase::Ptr_t child)
{
    // Add the child to this entity
    if(m_childrenMap.count(child->GetFullName()) == 0) {
        m_children.push_back(child);
        m_childrenMap.insert(std::make_pair(child->GetFullName(), child));
        child->m_parent = this;
    }
}

void PHPEntityBase::RecursivePrintStdout(PHPEntityBase::Ptr_t parent, int indent) { PrintStdout(indent); }

PHPEntityBase::Ptr_t PHPEntityBase::FindChild(const wxString& name, bool tryPrependingDollar) const
{
    PHPEntityBase::Map_t::const_iterator iter = m_childrenMap.find(name);
    if(iter != m_childrenMap.end()) {
        return iter->second;
    }

    // Could not find an exact match, try prepending
    if(tryPrependingDollar) {
        wxString modName = name;
        if(!modName.StartsWith("$")) {
            modName.Prepend("$");
        }
        iter = m_childrenMap.find(modName);
        if(iter != m_childrenMap.end()) {
            return iter->second;
        }
    }
    return PHPEntityBase::Ptr_t(NULL);
}

void PHPEntityBase::StoreRecursive(wxSQLite3Database& db)
{
    Store(db);
    // save the children
    PHPEntityBase::List_t::iterator iter = m_children.begin();
    for(; iter != m_children.end(); ++iter) {
        (*iter)->StoreRecursive(db);
    }
}

void PHPEntityBase::SetChildren(const PHPEntityBase::List_t& children)
{
    m_children.clear();
    m_childrenMap.clear();
    PHPEntityBase::List_t::const_iterator iter = children.begin();
    for(; iter != children.end(); ++iter) {
        AddChild(*iter);
    }
}

void PHPEntityBase::SetFullName(const wxString& fullname)
{
    m_fullname = fullname;
    m_shortName = m_fullname.AfterLast('\\');
}

void PHPEntityBase::RemoveChild(PHPEntityBase::Ptr_t child)
{
    // Remove the child from the map
    if(m_childrenMap.count(child->GetFullName())) {
        m_childrenMap.erase(child->GetFullName());
    }
    
    // Remove the child from the list as well
    PHPEntityBase::List_t::iterator iter =
        std::find_if(m_children.begin(), m_children.end(), [&](PHPEntityBase::Ptr_t c) {
            if(c->GetFullName() == child->GetFullName()) {
                return true;
            }
            return false;
        });

    if(iter != m_children.end()) {
        m_children.erase(iter);
    }
    child->m_parent = NULL;
}