Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CDiaInst.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Sun Aug 15 01:53:13 2010 UTC (13 years, 9 months ago) by okadu
File MIME type: text/x-c++src
File size: 9105 byte(s)


1 #include "stdafx.h"
2 #include "CListView.h"
3 #include "CDiaInst.h"
4
5 // 関数宣言
6 void *ReplaceAdr(void *);
7
8 // 外部グローバル
9 extern map<void *, void *> g_AddressMap;
10
11 /*
12 * コンストラクタ
13 */
14 CDiaElementBase::CDiaElementBase(){
15 m_ListElement = NULL;
16 }
17
18 /*
19 * リスト要素文字列更新
20 */
21 void CDiaElementBase::UpdateCaption(){
22 if(m_ListElement) m_ListElement->SetString(0, (char *)GetListCaption().c_str());
23 }
24
25 ////////////////////////////////////////////////////////////////////////////////
26 ////////////////////////////////////////////////////////////////////////////////
27
28 /*
29 * コンストラクタ
30 */
31 CDiaListBase::CDiaListBase(){
32 m_UseDefault = true;
33 }
34
35 /*
36 * 要素解放
37 */
38 void CDiaListBase::Free(){
39 IPDiaElementBase ipde = m_DiaList.begin();
40 for(; ipde!=m_DiaList.end(); ipde++) DELETE_V(*ipde);
41 m_DiaList.clear();
42 }
43
44 /*
45 * 要素リスト作成
46 */
47 void CDiaListBase::ListElement(
48 CListView *lv, // リストビュー
49 int sel // 選択位置
50 ){
51 lv->DeleteAllItems();
52 if(!Size()) m_DiaList.push_back(NewEntry());
53 IPDiaElementBase ipde = m_DiaList.begin();
54 for(; ipde!=m_DiaList.end(); ipde++){
55 CListElement *le = lv->InsertItem(-1, (char *)(*ipde)->GetListCaption().c_str());
56 (*ipde)->m_ListElement = le;
57 le->SetData((DWORD)(*ipde));
58 }
59 if(sel<0){
60 if(!m_UseDefault){
61 lv->SetSelectionMark(0, 0);
62 lv->EnsureVisible(0);
63 }
64 }else{
65 lv->SetSelectionMark(sel, 0);
66 lv->EnsureVisible(sel);
67 }
68 }
69
70 /*
71 * 要素追加
72 */
73 int CDiaListBase::AddElement(
74 CDiaElementBase *el // この後に追加
75 ){
76 int i = 0;
77 IPDiaElementBase ipde = m_DiaList.begin();
78 for(; ipde!=m_DiaList.end(); ipde++, i++){
79 if(*ipde==el){
80 m_DiaList.insert(++ipde, NewEntry());
81 return i+1;
82 }
83 }
84 m_DiaList.insert(ipde, NewEntry());
85 return i;
86 }
87
88 /*
89 * 要素削除
90 */
91 int CDiaListBase::DeleteElement(
92 CDiaElementBase *el // 削除要素
93 ){
94 int i = 0;
95 IPDiaElementBase ipde = m_DiaList.begin();
96 for(; ipde!=m_DiaList.end(); ipde++, i++){
97 if(*ipde==el){
98 DELETE_V(*ipde);
99 ipde = m_DiaList.erase(ipde);
100 return ipde==m_DiaList.end() ? i-1 : i;
101 }
102 }
103 return -1;
104 }
105
106 /*
107 * 要素回転
108 */
109 void CDiaListBase::RotateElement(
110 bool prev // 逆回転
111 ){
112 if(Size()<2) return;
113 if(prev) m_DiaList.splice(m_DiaList.begin(), m_DiaList, --m_DiaList.end(), m_DiaList.end());
114 else m_DiaList.splice(m_DiaList.end(), m_DiaList, m_DiaList.begin(), ++m_DiaList.begin());
115 }
116
117 /*
118 * 最初の要素を取得し、ひとつ送る
119 */
120 CDiaElementBase *CDiaListBase::DequeueBase(bool rotate){
121 if(m_DiaList.size()){
122 CDiaElementBase *ret = *m_DiaList.begin();
123 if(rotate) RotateElement(false);
124 return ret;
125 }else{
126 m_DiaList.push_back(NewEntry());
127 return *m_DiaList.begin();
128 }
129 }
130
131 /*
132 * 読込
133 */
134 char *CDiaListBase::Read(
135 char *str, // 対象文字列
136 CTrainGroup **gadr // 編成アドレス格納先
137 ){
138 char *eee, *tmp;
139 if(!(str = BeginBlock(str, Label()))) return NULL;
140 if(!(str = AsgnPointer(eee = str, "TrainGroup", (void **)gadr))) throw CSynErr(eee);
141 if(!(str = AsgnYesNo(eee = str, "UseDefault", &m_UseDefault))) throw CSynErr(eee);
142 while(true){
143 CDiaElementBase *de = NewEntry();
144 if(tmp = de->Read(str)){
145 str = tmp;
146 m_DiaList.push_back(de);
147 }else{
148 delete de;
149 break;
150 }
151 }
152 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
153 return str;
154 }
155
156 /*
157 * 保存
158 */
159 void CDiaListBase::Save(
160 FILE *df, // ファイル
161 char *ind, // インデント
162 CTrainGroup *group // 編成
163 ){
164 string ind2 = string(ind)+"\t";
165 fprintf(df, "%s%s{\n", ind, Label());
166 fprintf(df, "%s\tTrainGroup = %p;\n", ind, group);
167 fprintf(df, "%s\tUseDefault = %s;\n", ind, YESNO[m_UseDefault]);
168 IPDiaElementBase ipde = m_DiaList.begin();
169 for(; ipde!=m_DiaList.end(); ipde++) (*ipde)->Save(df, (char *)ind2.c_str());
170 fprintf(df, "%s}\n", ind);
171 }
172
173 ////////////////////////////////////////////////////////////////////////////////
174 ////////////////////////////////////////////////////////////////////////////////
175
176 /*
177 * デストラクタ
178 */
179 CDiaInstBase::~CDiaInstBase(){
180 IPDiaListBase ipdl = m_DiaMap.begin();
181 for(; ipdl!=m_DiaMap.end(); ipdl++){
182 ipdl->second->Free();
183 DELETE_V(ipdl->second);
184 }
185 }
186
187 /*
188 * ダイヤリスト検索
189 */
190 CDiaListBase *CDiaInstBase::Search(
191 CTrainGroup *group // 編成
192 ){
193 CDiaListBase *&dlist = m_DiaMap[group];
194 if(!dlist){
195 dlist = NewEntry();
196 if(!group) dlist->m_UseDefault = false;
197 }
198 return dlist;
199 }
200
201 /*
202 * ダイヤリスト検索 (デフォルト設定ならデフォルトを返す)
203 */
204 CDiaListBase *CDiaInstBase::SearchEffectBase(
205 CTrainGroup *group // 編成
206 ){
207 if(!m_DiaMap.count(group)) return Search(NULL);
208 CDiaListBase *dlist = m_DiaMap[group];
209 if(dlist->m_UseDefault) return Search(NULL);
210 return dlist;
211 }
212
213 /*
214 * アドレス復元
215 */
216 void CDiaInstBase::RestoreAddress(){
217 map<CTrainGroup *, CDiaListBase *> diamap;
218 IPDiaListBase ipdl = m_DiaMap.begin();
219 for(; ipdl!=m_DiaMap.end(); ipdl++)
220 diamap[(CTrainGroup *)ReplaceAdr(ipdl->first)] = ipdl->second;
221 m_DiaMap = diamap;
222 }
223
224 /*
225 * 読込
226 */
227 char *CDiaInstBase::Read(
228 char *str // 対象文字列
229 ){
230 char *eee, *tmp;
231 if(!(str = BeginBlock(str, Label()))) return NULL;
232 if(!(str = AsgnString(eee = str, "Name", &m_Name))) throw CSynErr(eee);
233 m_Name = RestoreDoubleQuote(m_Name);
234 while(true){
235 CTrainGroup *group;
236 CDiaListBase *dlist = NewEntry();
237 if(tmp = dlist->Read(str, &group)){
238 str = tmp;
239 m_DiaMap[group] = dlist;
240 }else{
241 delete dlist;
242 break;
243 }
244 }
245 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
246 return str;
247 }
248
249 /*
250 * 保存
251 */
252 void CDiaInstBase::Save(
253 FILE *df, // ファイル
254 char *ind // インデント
255 ){
256 string ind2 = string(ind)+"\t";
257 fprintf(df, "%s%s{\n", ind, Label());
258 fprintf(df, "%s\tName = \"%s\";\n", ind, ExpandDoubleQuote(m_Name).c_str());
259 IPDiaListBase ipdl = m_DiaMap.begin();
260 for(; ipdl!=m_DiaMap.end(); ipdl++) ipdl->second->Save(
261 df, (char *)ind2.c_str(), ipdl->first);
262 fprintf(df, "%s}\n", ind);
263 }
264
265 ////////////////////////////////////////////////////////////////////////////////
266 ////////////////////////////////////////////////////////////////////////////////
267
268 /*
269 * コンストラクタ
270 */
271 CPointElement::CPointElement(){
272 m_PointSwitch = 0;
273 }
274
275 /*
276 * リスト文字列取得
277 */
278 string CPointElement::GetListCaption(){
279 static char *cap[3] = {lang(Random), lang(Left), lang(Right)};
280 return cap[m_PointSwitch];
281 }
282
283 /*
284 * ポイント計算
285 */
286 int CPointElement::CalcPoint(){
287 return m_PointSwitch ? m_PointSwitch-1 : Rand(2);
288 }
289
290 /*
291 * 読込
292 */
293 char *CPointElement::Read(
294 char *str // 対象文字列
295 ){
296 if(!(str = AsgnInteger(str, "Point", &m_PointSwitch))) return NULL;
297 return str;
298 }
299
300 /*
301 * 保存
302 */
303 void CPointElement::Save(
304 FILE *df, // ファイル
305 char *ind // インデント
306 ){
307 fprintf(df, "%sPoint = %d;\n", ind, m_PointSwitch);
308 }
309
310 ////////////////////////////////////////////////////////////////////////////////
311 ////////////////////////////////////////////////////////////////////////////////
312
313 /*
314 * コンストラクタ
315 */
316 CDiaElement::CDiaElement(){
317 m_Action = 0;
318 m_TimeType = 0;
319 m_Hour = 1;
320 m_Minute = 0;
321 m_Second = 0;
322 // m_Joint = 0;
323 m_Offset = 0.0f;
324 }
325
326 /*
327 * リスト文字列取得
328 */
329 string CDiaElement::GetListCaption(){
330 char *timetype[2] = {lang(Duration), lang(Time)};
331 string ret;
332 switch(m_Action){
333 case 0:
334 ret = FlashIn("%s / %s %02d:%02d:%02d",
335 lang(Stop), timetype[m_TimeType], m_Hour, m_Minute, m_Second);
336 break;
337 case 1:
338 ret = FlashIn("%s / %s %02d:%02d:%02d",
339 lang(Return), timetype[m_TimeType], m_Hour, m_Minute, m_Second);
340 break;
341 case 2:
342 ret = lang(Pass);
343 break;
344 }
345 // if(m_Joint) ret += " / 連結";
346 return ret;
347 }
348
349 /*
350 * 読込
351 */
352 char *CDiaElement::Read(
353 char *str // 対象文字列
354 ){
355 char *eee;
356 if(!(str = BeginBlock(str, "DiaElement"))) return NULL;
357 if(!(str = AsgnInteger(eee = str, "Action", &m_Action))) throw CSynErr(eee);
358 if(!(str = AsgnInteger(eee = str, "TimeType", &m_TimeType))) throw CSynErr(eee);
359 if(!(str = Assignment(eee = str, "Time"))) throw CSynErr(eee);
360 if(!(str = ConstInteger(eee = str, &m_Hour))) throw CSynErr(eee);
361 if(!(str = Character2(eee = str, ','))) throw CSynErr(eee);
362 if(!(str = ConstInteger(eee = str, &m_Minute))) throw CSynErr(eee);
363 if(!(str = Character2(eee = str, ','))) throw CSynErr(eee);
364 if(!(str = ConstInteger(eee = str, &m_Second))) throw CSynErr(eee);
365 if(!(str = Character2(eee = str, ';'))) throw CSynErr(eee);
366 if(!(str = AsgnFloat(eee = str, "Offset", &m_Offset))) throw CSynErr(eee);
367 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
368 return str;
369 }
370
371 /*
372 * 保存
373 */
374 void CDiaElement::Save(
375 FILE *df, // ファイル
376 char *ind // インデント
377 ){
378 fprintf(df, "%sDiaElement{\n", ind);
379 fprintf(df, "%s\tAction = %d;\n", ind, m_Action);
380 fprintf(df, "%s\tTimeType = %d;\n", ind, m_TimeType);
381 fprintf(df, "%s\tTime = %d, %d, %d;\n", ind, m_Hour, m_Minute, m_Second);
382 fprintf(df, "%s\tOffset = %f;\n", ind, m_Offset);
383 fprintf(df, "%s}\n", ind, m_Offset);
384 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26