source: dev/trunk/jenga/include/smoothie/Parameter.h@ 181

Last change on this file since 181 was 181, checked in by dai_9181, 17 years ago
File size: 2.1 KB
Line 
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include "Type.h"
7#include "BasicFixed.h"
8
9class Parameter : public Type
10{
11 std::string varName;
12 bool isRef;
13 bool isArray;
14 int subScripts[MAX_ARRAYDIM];
15
16 const std::string initValue;
17
18public:
19 Parameter( const std::string &varName, const Type &type, bool isRef = false, const std::string initValue = "" ):
20 Type( type ),
21 varName( varName ),
22 isRef( isRef ),
23 isArray( false ),
24 initValue( initValue )
25 {
26 subScripts[0] = -1;
27 }
28 Parameter( const Parameter &param ):
29 Type( param ),
30 varName( param.varName ),
31 isRef( param.isRef ),
32 isArray( false ),
33 initValue( param.initValue )
34 {
35 subScripts[0] = -1;
36 if( param.isArray ){
37 SetArray( param.subScripts );
38 }
39 }
40 ~Parameter(){}
41
42 void SetArray( const int *pSubScripts ){
43 isArray = true;
44 memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
45 }
46
47 const std::string &GetVarName() const
48 {
49 return varName;
50 }
51
52 bool IsRef() const
53 {
54 return isRef;
55 }
56 bool IsArray(){
57 return isArray;
58 }
59 int *GetSubScriptsPtr(){
60 return subScripts;
61 }
62
63 const std::string &GetInitValue() const
64 {
65 return initValue;
66 }
67
68 bool Equals( const Parameter &param ) const
69 {
70 if( Type::Equals( param ) ){
71 return true;
72 }
73 else{
74
75 if( this->isRef && this->GetBasicType() == DEF_ANY &&
76 param.isRef == false && param.IsPointer()
77 ||
78 this->isRef == false && this->IsPointer() &&
79 param.isRef && param.GetBasicType() == DEF_ANY ){
80 /* ByRef var As Any
81
82 var As VoidPtr
83 は同等
84 */
85 return true;
86 }
87 }
88
89 return false;
90 }
91};
92
93class Parameters : public std::vector<Parameter *>
94{
95public:
96
97 bool Equals( const Parameters &params ) const
98 {
99 if( this->size() != params.size() ){
100 return false;
101 }
102
103 int max = (int)this->size();
104 for( int i=0; i<max; i++ ){
105 if( !(*this)[i]->Equals( *params[i] ) ){
106 return false;
107 }
108 }
109
110 return true;
111 }
112
113 int GetMemorySize() const
114 {
115 return (int)this->size() * PTR_SIZE;
116 }
117};
Note: See TracBrowser for help on using the repository browser.