[EXaml] Add code for load EXaml
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / EXaml / Action / GetValueAction.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Tizen.NUI.Binding;
5
6 namespace Tizen.NUI.EXaml
7 {
8     internal class GetValueAction : Action
9     {
10         public GetValueAction(char sign, Action parent)
11         {
12             this.sign = sign;
13             this.parent = parent;
14         }
15         private char sign;
16         private Action parent;
17
18         private delegate object GetValueByString(string value);
19
20         private static GetValueByString[] getValueByStrings = null;
21         private static GetValueByString[] GetValueByStrings
22         {
23             get
24             {
25                 if (null == getValueByStrings)
26                 {
27                     getValueByStrings = new GetValueByString['p' - 'a' + 2];
28
29                     getValueByStrings[0] = (string value) =>
30                     {
31                         return value;
32                     };
33
34                     //'a' -> 1 Ojbect
35                     getValueByStrings[1] = (string value) =>
36                     {
37                         int index = int.Parse(value);
38                         return new Instance(index);
39                     };
40
41                     //b SByte
42                     getValueByStrings[2] = (string value) =>
43                     {
44                         return SByte.Parse(value);
45                     };
46
47                     //c Int16
48                     getValueByStrings[3] = (string value) =>
49                     {
50                         return Int16.Parse(value);
51                     };
52
53                     //d Int32
54                     getValueByStrings[4] = (string value) =>
55                     {
56                         return Int32.Parse(value);
57                     };
58
59                     //e Int64
60                     getValueByStrings[5] = (string value) =>
61                     {
62                         return Int64.Parse(value);
63                     };
64
65                     //f Byte
66                     getValueByStrings[6] = (string value) =>
67                     {
68                         return Byte.Parse(value);
69                     };
70
71                     //g UInt16
72                     getValueByStrings[7] = (string value) =>
73                     {
74                         return UInt16.Parse(value);
75                     };
76
77                     //h UInt32
78                     getValueByStrings[8] = (string value) =>
79                     {
80                         return UInt32.Parse(value);
81                     };
82
83                     //i UInt64
84                     getValueByStrings[9] = (string value) =>
85                     {
86                         return UInt64.Parse(value);
87                     };
88
89                     //j Single
90                     getValueByStrings[10] = (string value) =>
91                     {
92                         return Single.Parse(value);
93                     };
94
95                     //k Double
96                     getValueByStrings[11] = (string value) =>
97                     {
98                         return Double.Parse(value);
99                     };
100
101                     //l Boolean
102                     getValueByStrings[12] = (string value) =>
103                     {
104                         return Boolean.Parse(value);
105                     };
106
107                     //m TimeSpan
108                     getValueByStrings[13] = (string value) =>
109                     {
110                         return TimeSpan.Parse(value);
111                     };
112
113                     //n decimal
114                     getValueByStrings[14] = (string value) =>
115                     {
116                         return decimal.Parse(value);
117                     };
118
119                     //o enum
120                     getValueByStrings[15] = (string value) =>
121                     {
122                         //Should be deal prev
123                         return null;
124                     };
125                 }
126
127                 return getValueByStrings;
128             }
129         }
130
131         public Action DealChar(char c)
132         {
133             if (c == sign)
134             {
135                 switch (sign)
136                 {
137                     case '\"':
138                         Value = GetValueByStrings[0](valueString);
139                         break;
140
141                     case 'z':
142                         Value = null;
143                         break;
144
145                     default:
146                         Value = GetValueByStrings[c - 'a' + 1](valueString);
147                         break;
148                 }
149
150                 parent?.OnActive();
151                 return parent;
152             }
153
154             if ('\"' != sign)
155             {
156                 switch (c)
157                 {
158                     case ' ':
159                     case '\n':
160                     case '\r':
161                         return this;
162
163                     case '(':
164                         getValueList = new GetValueListAction(')', this);
165                         return getValueList;
166                 }
167             }
168
169             valueString += c;
170
171             return this;
172         }
173
174         private string valueString;
175
176         private GetValueListAction getValueList;
177
178         public object Value
179         {
180             get;
181             private set;
182         }
183
184         public void Init()
185         {
186             valueString = "";
187         }
188
189         public void OnActive()
190         {
191         }
192     }
193 }