473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2047

"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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.