473,385 Members | 2,044 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,385 software developers and data experts.

What structure to choose

Hi,

I would like to associate a couple of value(SFID and nRecNo) with a byte
array.
So I tried the following structure :

typedef std::vector<BYTE> ByteArray;

class CardIndex
{
public:

CDataIndex(int nSFID, int nRecNo){ m_nSFID = nSFID; m_nRecNo = nRecNo; }

int m_nSFID;
int m_nRecNo;
};
class CCardData
{
public:
CCardData();
virtual ~CCardData();

private:
int AddTag(int nSFID, int nRecNo);

map<CardIndex, ByteArray> m_FileData;
}

CCardData::AddTag(int nSFID, int nRecNo)
{

m_FileData[new CardIndex(nSFID, nRecNo) ] = new ByteArray
return 0;
}
but it cannot work.
I don't think this structure is good. How would you do it ?
For instance I want ta declare several buffer like this :

Jul 23 '05 #1
1 1295
Vince wrote in news:42**********************@news.free.fr in
comp.lang.c++:
Hi,

I would like to associate a couple of value(SFID and nRecNo) with a
byte array.
So I tried the following structure :

typedef std::vector<BYTE> ByteArray;

class CardIndex
{
public:

CDataIndex(int nSFID, int nRecNo){ m_nSFID = nSFID; m_nRecNo =
nRecNo; }

int m_nSFID;
int m_nRecNo;
bool operator < ( CDataIndex const & rhs ) const
{
return m_nSFID == rhs.m_nSFID ?
m_nRecNo < rhs.m_nRecNo : m_nSFID < rhs.m_nSFID
;
}
};
class CCardData
{
public:
CCardData();
virtual ~CCardData();

private:
int AddTag(int nSFID, int nRecNo);

map<CardIndex, ByteArray> m_FileData;
A std::map<> 's KeyType must be Have "Strict Weak Ordering" or
you must give a third "functor" argument to std::map<> that
provides this ordering.

The simplest way to do this in this case is to provide the
defenition of operator < () as I did above.
}

CCardData::AddTag(int nSFID, int nRecNo)
{

m_FileData[new CardIndex(nSFID, nRecNo) ] = new ByteArray
return 0;
}
but it cannot work.
I don't think this structure is good. How would you do it ?
For instance I want ta declare several buffer like this :


You could also use std::pair<> :

#include <ostream>
#include <iostream>
#include <iomanip>
#include <map>
#include <utility>
#include <vector>

typedef
std::map< std::pair< int, int >, std::vector< unsigned char > >
CCardData
;
int main()
{
CCardData ccd;

for ( int i = 0; i < 10; ++i )
for ( int j = 0; j < 10; ++j )
{
std::vector< unsigned char > &buf = ccd[ std::make_pair( i, j ) ];
for ( unsigned c = 0; c < 256; ++c )
{
buf.push_back( (unsigned char)c );
}
}

std::vector< unsigned char > &buf = ccd[ std::make_pair( 4, 5 ) ];

std::vector< unsigned char >::iterator ptr, lim;
ptr = buf.begin();
lim = buf.end();

for (; ptr != lim; ++ptr )
{
std::cout << std::hex << unsigned(*ptr) << '\n';
}
}

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #2

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

Similar topics

2
by: ragha | last post by:
Dear friends I am emulating thr tree structure mentioned in the article http://www.15seconds.com/issue/010921.htm I have succesfully created the folder structure for level 2 I need this...
2
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
4
by: hufel | last post by:
Hi, I'm doing my first big project in C# and I'm stuck with a problem that I believe has a simple and efficient solution for it (I just haven't bumped into it yet...). The concept is the...
4
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type...
5
by: Matias | last post by:
I'm not asking if it's better or not than php... I want to know the opinions of web developers about this new toy... Byee..
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
14
by: zoltan | last post by:
Hi, Consider a structure as follows : struct dummy { int a; int b; int c; };
6
by: jason | last post by:
Hello, I have a question about what kind of datastructure to use. I'm reading collumn based data in the form of: 10\t12\t9\t11\n 24\t11\t4\t10\n ..... I now have a structure which allows me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.