472,976 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 software developers and data experts.

Cannot find a data structure for this problem

I have a very specific problem to solve but I cannot find a data
structure for it.
I don't know if I am posting on the good newsgroup but I cannot find
a software.design group.
I would like to declare a smart structure initialized via a XML file.
The goal of this structure is to store data from a smart card.

My XML file describes the file structure of my smart card. On a smart
card file are identified by number(sfid) and not by their name like on
PC. And each record are BYTE arrays

<CardMapping>
<CardFile sfid="Ox17">
<CardRecord index="1" size="29">
<CardData
offset="0"
size="20 bytes"
type="string"
name="Last Name1"
/>
<CardData
offset="20"
size="1 bytes"
type="numeric"
name="age1"/>
</CardRecord>
</CardFile>

<CardFile sfid="Ox18">
<CardRecord index="1" size="29">
<CardData
offset="0"
size="20 bytes"
type="string"
name="Last Name2"
/>
<CardData
offset="20"
size="2 bytes"
type="numeric"
name="age2"/>
</CardRecord>
</CardFile>

</CardMapping>

So basically a smart card can have 0 or n files (CardFile) with inside 0
or n records and each records is splitted into chunks of data.
After reading a file like this I should have :

File 0x17
----------------
| |
|Record1 xxxxx |
|Record2 xxxxx |
|... |
|Recordn xxxx |
| |
| |
----------------

File 0x18
----------------
| |
|Record1 xxxxx |
|Record2 xxxxx |
|... |
|Recordn xxxx |
| |
| |
----------------

And finally what I want to do is something like,
CString csName = m_Card.GetData("Last Name1") (it should extract data
from first record and convert it into string.
int nAge = m_Card.GetData("age2").


Jul 22 '05 #1
2 2030

"Vince" <vs**@caramail.com> schreef in bericht
news:41**********************@news.free.fr...
I have a very specific problem to solve but I cannot find a data structure
for it.
I don't know if I am posting on the good newsgroup but I cannot find
a software.design group.
I would like to declare a smart structure initialized via a XML file. The
goal of this structure is to store data from a smart card.

My XML file describes the file structure of my smart card. On a smart card
file are identified by number(sfid) and not by their name like on PC. And
each record are BYTE arrays

<CardMapping>
<CardFile sfid="Ox17">
<CardRecord index="1" size="29">
<CardData
offset="0"
size="20 bytes"
type="string"
name="Last Name1"
/>
<CardData
offset="20"
size="1 bytes"
type="numeric"
name="age1"/>
</CardRecord>
</CardFile>

<CardFile sfid="Ox18">
<CardRecord index="1" size="29">
<CardData
offset="0"
size="20 bytes"
type="string"
name="Last Name2"
/>
<CardData
offset="20"
size="2 bytes"
type="numeric"
name="age2"/>
</CardRecord>
</CardFile>
</CardMapping>

So basically a smart card can have 0 or n files (CardFile) with inside 0
or n records and each records is splitted into chunks of data.
After reading a file like this I should have :

File 0x17 ----------------
| |
|Record1 xxxxx |
|Record2 xxxxx |
|... |
|Recordn xxxx |
| |
| |
----------------

File 0x18
----------------
| |
|Record1 xxxxx |
|Record2 xxxxx |
|... |
|Recordn xxxx |
| |
| |
----------------

And finally what I want to do is something like,
CString csName = m_Card.GetData("Last Name1") (it should extract data from
first record and convert it into string.
int nAge = m_Card.GetData("age2").




Hi,

I think something like

struct CardData
{
int offset;
int size;
string type;
string name;
};

struct CardMapping
{
public :
string CardFile;
int index;
int size;
struct CardData** carddata;
};

int main(int argc, char** argv[])
{
int count = 10;
CardMapping map;
map.carddata = new CardData *[count * sizeof(CardData*)];

for(int i = 0; i < count; i++)
{
map.carddata[i] = new CardData;
}

return 0;
}

Johan


Jul 22 '05 #2
In message <10*************@corp.supernews.com>, Johan <me@knoware.nl>
writes

"Vince" <vs**@caramail.com> schreef in bericht
news:41**********************@news.free.fr...
I have a very specific problem to solve but I cannot find a data structure
for it.
I don't know if I am posting on the good newsgroup but I cannot find
a software.design group.
I would like to declare a smart structure initialized via a XML file. The
goal of this structure is to store data from a smart card.

My XML file describes the file structure of my smart card. On a smart card
file are identified by number(sfid) and not by their name like on PC. And
each record are BYTE arrays
[...]
So basically a smart card can have 0 or n files (CardFile) with inside 0
or n records and each records is splitted into chunks of data.

[...]
Hi,

I think something like
I don't. Read on...
struct CardData
{
int offset;
int size;
string type;
string name;
};

struct CardMapping
{
public :
string CardFile;
int index;
int size;
struct CardData** carddata;
};

int main(int argc, char** argv[])
{
int count = 10;
CardMapping map;
map.carddata = new CardData *[count * sizeof(CardData*)];

for(int i = 0; i < count; i++)
{
map.carddata[i] = new CardData;
}

return 0;
}


I think that's *horrible*. Not only are you messing with raw pointers to
arrays of pointers, which is just asking for memory leaks or worse,
you're doing it outside the class, which breaks any pretence at
encapsulation before you even start. Your struct will get a
compiler-defined assignment, copy constructor and destructor, which are
completely inappropriate for something with pointer members and will
cause UB the moment you double-delete something, which is almost
inevitably waiting to happen. In short, it's a nightmare. C++ provides
far better ways of working.

I'd suggest:

Don't write C code in C++.

Use standard containers (std::vector is probably appropriate here.)

Don't use pointers if you don't have to. Copying a few objects in and
out of vectors is probably a small price to pay, compared with managing
pointers to them.

Encapsulate. Use class, not struct, make member data private and provide
appropriate access functions. Make the classes read themselves if
possible, via member or friend functions.

HTH.
--
Richard Herring
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
12
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
4
by: Koen | last post by:
Hi all, At work I created a database which is really helpful. The database is used by approx 15 users. Everything worked great, until I added some 'scoreboard' forms and reports. I get the...
3
by: nicolas.bouchard | last post by:
I am developing an integration process between two databases. One of them is a SQL Server 2000 and the other is using MSDE 2000. The integration process is done in C# (VS2003). The main database...
0
by: Alan Isaac | last post by:
This is really a repackaging of an earlier question, probably illustrating that I still do not understand relative imports. Suppose I have the package structure (taken from the example at...
0
by: SMH | last post by:
Hi All, I am currently learning .Net 2, studying for 70-528. I've hit a bit of a brick wall with DataColumn.Expression. As I understand it, this can be used to (For example) concatenate two...
1
by: colin | last post by:
Hi, I have this code wich fills in data fields from a file, recursivley down through any structures/classes the difficulty is when I come acros a field wich is a structure, wich can not be read...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.