473,799 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2078

"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.supernew s.com>, Johan <me@knoware.n l>
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
6468
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_ { char szInput; char szOutput; int iSum;
12
7000
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 unambigous tree structure. The root node can have whatever value you prefer, I suppose NULL would be good for a start. What I want to do is finding the way from an arbitrary node in the tree. Example:
8
5483
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
10
4475
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 Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
4
3293
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 "Cannot open any more databases" error. The 'scoreboard' form show a matrix of 6 columns, 7 rows. Each cell is calculated separate by (what I call complex) queries.
3
21873
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 is the SQL Server, the MSDE will contain a really small subset of the data found on the main. To help diminish the amount of time taken to develop an integration process between those databases, the same structure are found on both side. The only...
0
1198
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 http://www.python.org/dev/peps/pep-0328/) package/ __init__.py subpackage1/ __init__.py
0
4574
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 columns to make a derived column. When I run my code, I get this error: ------------
1
2343
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 as a binary blit. I need to be able to pass this as a reference to a function to carry on the recursion through each field... I have tried to use TypeReferences but I get this error and I cant find anything much about it.
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.