Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/FeliCa2Money-1/Card.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 204 - (show annotations) (download) (as text)
Sun May 18 04:21:26 2008 UTC (15 years, 10 months ago) by tmurakam
File MIME type: text/x-c++src
File size: 2949 byte(s)
Move older version (ver 1.x)

1 /*
2 * FeliCa2Money
3 *
4 * Copyright (C) 2001-2007 Takuya Murakami
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 //---------------------------------------------------------------------------
21
22 #include <vcl.h>
23 #pragma hdrstop
24 #include <stdio.h>
25
26 #include "Card.h"
27
28 /// コンストラクタ
29 Card::Card()
30 {
31 prev_key = serial = 0;
32 }
33
34 /// デストラクタ
35 Card::~Card()
36 {
37 vector<Transaction*>::iterator it;
38
39 for (it = list.begin(); it != list.end(); it++) {
40 delete *it;
41 }
42 }
43
44 /**
45 @brief トランザクションIDの生成
46 @param[in] キー
47 @return シリアル番号
48
49 キーが前回と異なっていれば常に 0 を返す
50 同じ場合はシリアル番号をインクリメントして返す
51 */
52 int Card::GenerateTransactionId(int key)
53 {
54 if (key != prev_key) {
55 serial = 0;
56 prev_key = key;
57 } else {
58 serial++;
59 }
60 return serial;
61 }
62
63 /**
64 @brief タブで区切られた各行を解析する
65 @param[in] lines 処理する行(複数行)
66 @param[in] reverse 逆順に処理するかどうかのフラグ
67 @return 0 で成功、-1 でエラー
68
69 解析結果は list に格納される
70 */
71 int CardWithLineParser::ParseLines(TStringList *lines, bool reverse)
72 {
73 char buf[3000];
74 AnsiString rows[30];
75 int i;
76 int start, incr, end, count, err;
77
78 count = lines->Count;
79 if (reverse) {
80 start = count - 1;
81 end = -1;
82 incr = -1;
83 } else {
84 start = 0;
85 end = count;
86 incr = 1;
87 }
88 for (i = start; i != end; i += incr) {
89 strncpy(buf, lines->Strings[i].c_str(), sizeof(buf));
90
91 // タブ区切りを分解
92 char *p;
93 char *pp = buf;
94
95 int n;
96 for (n= 0; (p = getTabbedToken(&pp)) != NULL; n++) {
97 rows[n] = p;
98 }
99
100 Transaction *t = GenerateTransaction(n, rows, &err);
101 if (!t) {
102 if (err) return -1; // fatal error
103 continue;
104 }
105
106 list.push_back(t);
107 }
108 return 0;
109 }
110
111 /**
112 @brief タブで区切られた token を取得する
113 @param[in,out] pos 読み込み位置
114 @return token
115 */
116 char * CardWithLineParser::getTabbedToken(char **pos)
117 {
118 char *ret = *pos;
119
120 if (*pos == NULL) {
121 return NULL; // no more token
122 }
123
124 char *nextpos = strchr(*pos, '\t');
125 if (nextpos) {
126 *nextpos = '\0';
127 *pos = nextpos + 1;
128 } else {
129 *pos = NULL; // no more token
130 }
131 return ret;
132 }

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