~dominik-burgdoerfer/libdmcc/trunk

« back to all changes in this revision

Viewing changes to src/PccClass.cpp

  • Committer: Dominik Burgdörfer
  • Date: 2009-10-16 22:30:52 UTC
  • Revision ID: dominik@domachine-20091016223052-n9p8wea6s1bh61tz
fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * =====================================================================================
 
3
 *
 
4
 *       Filename:  PccClass.cpp
 
5
 *
 
6
 *    Description:  
 
7
 *
 
8
 *        Version:  1.0
 
9
 *        Created:  05.10.2009 16:57:14
 
10
 *       Revision:  none
 
11
 *       Compiler:  gcc
 
12
 *
 
13
 *         Author:  Dominik 'domachine' Burgdoerfer (-), dominik.burgdoerfer@gmail.com
 
14
 *        Company:  
 
15
 *
 
16
 * =====================================================================================
 
17
 */
 
18
 
 
19
#define __DMCC_PCC
 
20
#    include "../dmcc/pcc/PccClass.hpp"
 
21
#undef __DMCC_PCC
 
22
#include "../dmcc/Constructor.hpp"
 
23
 
 
24
namespace dmcc {
 
25
    namespace pcc {
 
26
        /*
 
27
         * ==================================
 
28
         * dmcc::pcc::PccClass Implementation
 
29
         * ==================================
 
30
         */
 
31
 
 
32
        /*
 
33
         * ============
 
34
         * Constructors
 
35
         * ============
 
36
         */
 
37
 
 
38
        PccClass::PccClass(const std::string & name, const std::type_info * typeInfo) {
 
39
            this->mName = name;
 
40
            this->mTypeInfo = typeInfo;
 
41
            
 
42
        }
 
43
 
 
44
        /*
 
45
         * ===========
 
46
         * Destructors
 
47
         * ===========
 
48
         */
 
49
 
 
50
        PccClass::~PccClass() {
 
51
            unsigned int i;
 
52
 
 
53
            for(i = 0; i < mConstructors.size(); i++) {
 
54
                delete mConstructors.at(i);
 
55
            }
 
56
        }
 
57
 
 
58
        void PccClass::addConstructor(dmcc::Constructor * constructor) {
 
59
            this->mConstructors.push_back(constructor);
 
60
        }
 
61
 
 
62
        void PccClass::setContext(PluginContext * context) {
 
63
            this->mContext = context;
 
64
        }
 
65
 
 
66
        Constructor * PccClass::getConstructor(std::vector<boost::any> & params) {
 
67
            unsigned int i, j;
 
68
            for(i = 0; i < mConstructors.size(); i++) {
 
69
                unsigned int matched = 0;
 
70
    
 
71
                Constructor * current = mConstructors.at(i);
 
72
                std::vector<const pcc::Argument *> * currentArgs = current->arguments();
 
73
                
 
74
                for(j = 0; j < params.size(); j++) {
 
75
                    if(params.size() > currentArgs->size())
 
76
                        break;
 
77
                    if(params.at(j).type() == *currentArgs->at(j)->type()) {
 
78
                        matched++;
 
79
                    }
 
80
                    else {
 
81
                        break;
 
82
                    }
 
83
                }
 
84
    
 
85
                if(matched == params.size()) {
 
86
                    if(params.size() < currentArgs->size()) {
 
87
                        unsigned int rArgs;
 
88
                        unsigned int dArgs;
 
89
                        unsigned int iN;
 
90
    
 
91
                        rArgs = currentArgs->size() - params.size();
 
92
                        dArgs = 0;
 
93
    
 
94
                        for(iN = 0; iN < rArgs; iN++) {
 
95
                            boost::any * defaultArg = currentArgs->at(iN + params.size())->defaultArg();
 
96
                            if(defaultArg != 0) {
 
97
                                dArgs++;
 
98
                            }
 
99
                        }
 
100
    
 
101
                        if(dArgs == rArgs) {
 
102
                            for(iN = 0; iN < rArgs; iN++) {
 
103
                                boost::any * defaultArg = currentArgs->at(iN + params.size())->defaultArg();
 
104
                                if(defaultArg != 0) {
 
105
                                    params.push_back(*defaultArg);
 
106
                                }
 
107
                            }
 
108
                            
 
109
                            return current;
 
110
                        }
 
111
                    }
 
112
                    else
 
113
                        return current;
 
114
                }
 
115
            }
 
116
    
 
117
            return 0;
 
118
        }
 
119
    
 
120
        bool PccClass::operator==(const Class & clazz) {
 
121
            return *mTypeInfo == clazz.stdTypeInfo();
 
122
        }
 
123
    
 
124
        bool PccClass::operator!=(const Class & clazz) {
 
125
            return *mTypeInfo != clazz.stdTypeInfo();
 
126
        }
 
127
    
 
128
        bool PccClass::operator==(const std::type_info & typeInfo) {
 
129
            return *mTypeInfo == typeInfo;
 
130
        }
 
131
    
 
132
        bool PccClass::operator!=(const std::type_info & typeInfo) {
 
133
            return *mTypeInfo != typeInfo;
 
134
        }
 
135
    
 
136
        /*
 
137
         * ================
 
138
         * Property Methods
 
139
         * ================
 
140
         */
 
141
    
 
142
        std::string PccClass::name() const {
 
143
            return mName;
 
144
        }
 
145
    
 
146
        const std::type_info & PccClass::stdTypeInfo() const {
 
147
            return *mTypeInfo;
 
148
        }
 
149
    
 
150
        PluginContext * PccClass::context() const {
 
151
            return mContext;
 
152
        }
 
153
    }
 
154
}