~dominik-burgdoerfer/libdmcc/trunk

« back to all changes in this revision

Viewing changes to src/PccConstructor.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:  Constructor.cpp
 
5
 *
 
6
 *    Description:  
 
7
 *
 
8
 *        Version:  1.0
 
9
 *        Created:  23.08.2009 21:03:42
 
10
 *       Revision:  none
 
11
 *       Compiler:  gcc
 
12
 *
 
13
 *         Author:  Dominik 'domachine' Burgdoerfer (-), dominik.burgdoerfer@gmail.com
 
14
 *        Company:  
 
15
 *
 
16
 * =====================================================================================
 
17
 */
 
18
#define __DMCC_PCC
 
19
#    include "../dmcc/pcc/PccConstructor.hpp"
 
20
#undef __DMCC_PCC
 
21
 
 
22
using namespace std;
 
23
 
 
24
namespace dmcc {
 
25
    namespace pcc {
 
26
        /*
 
27
         * =====================================
 
28
         * dmcc::pcc::PccConstructor Implementation
 
29
         * =====================================
 
30
         */
 
31
        
 
32
        /*
 
33
         * ============
 
34
         * Constructors
 
35
         * ============
 
36
         */
 
37
        
 
38
        PccConstructor::PccConstructor(const std::string & name,
 
39
                vector<const Argument *> * arguments,
 
40
                const std::string & str)
 
41
                
 
42
            : _name(name), _string(str), _arguments(arguments) {
 
43
        }
 
44
        
 
45
        /*
 
46
         * ===========
 
47
         * Destructors
 
48
         * ===========
 
49
         */
 
50
        
 
51
        PccConstructor::~PccConstructor() {
 
52
            unsigned int i;
 
53
            for(i = 0; i < _arguments->size(); i++) {
 
54
                delete _arguments->at(i);
 
55
            }
 
56
            delete _arguments;
 
57
        }
 
58
        
 
59
        /*
 
60
         * ==============
 
61
         * Public Methods
 
62
         * ==============
 
63
         */
 
64
 
 
65
        boost::any PccConstructor::newInstance(const std::vector<boost::any> & params) {
 
66
            typedef boost::any (*Constr)(const std::vector<boost::any> &);
 
67
 
 
68
            Constr pConstr;
 
69
            boost::any pObject;
 
70
 
 
71
            pConstr = (Constr)mDeclaringClass->context()->symbol(mSymbolName);
 
72
 
 
73
            if(pConstr == 0)
 
74
                 throw LoadException(mDeclaringClass->context()->lastError());
 
75
 
 
76
            pObject = (*pConstr)(params);
 
77
 
 
78
            return pObject;
 
79
 
 
80
        }
 
81
 
 
82
        void PccConstructor::setSymbolName(const std::string & symbolName) {
 
83
            this->mSymbolName = symbolName;
 
84
        }
 
85
        
 
86
        string PccConstructor::name() const {
 
87
            return _name;
 
88
        }
 
89
        
 
90
        string PccConstructor::string() const {
 
91
            return _string;
 
92
        }
 
93
        
 
94
        vector<const Argument *> * PccConstructor::arguments() const {
 
95
            return _arguments;
 
96
        }
 
97
 
 
98
        dmcc::Class * PccConstructor::declaringClass() const {
 
99
            return mDeclaringClass;
 
100
        }
 
101
 
 
102
        void PccConstructor::setDeclaringClass(Class * clazz) {
 
103
            mDeclaringClass = clazz;
 
104
        }
 
105
    }
 
106
}