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

Updating <map> Structure - Help!

I'm having difficulty updating map objects. In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.

struct ChipRecord // Chip Times record
{
time_t hiStartTime; // Start Time
// much more...
} timeWork; // entrant info records
typedef map<int, ChipRecordBCI;
BCI bci;
map<int, ChipRecord>::iterator bIter;

int nBib = 17;
time_t cTime = 11151544;

// initialize and populate "timeWork" structure, etc.
bci.insert(bci::value_type(bibNumber, timeWork));
//...
// obtain a cTime value...
bIter = bci.find(nBib);
if(bIter != bci.end())
{
timeWork = bIter->second; // ???
timeWork = bci.find(nBib)->second; // ???
timeWork = (*bIter).second; // ???
if(cTime timeWork.hiStartTime) // use highest time
{ // update the object
bIter->second.hiStartTime = cTime; // ???
timeWork.hiStartTime = cTime; // ???
} // if
} // if

It's the code directly above that doesn't do what I intend: change
the map object's value and update the object. There is much more going
on in the program, but this is the simplest amount that demonstrates the
issue. I don't know how to update the object. Please advise. TIA
Nov 17 '08 #1
5 3075
On Nov 17, 1:54*pm, mrc2...@cox.net (Mike Copeland) wrote:
* *I'm having difficulty updating map objects. *In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.

struct ChipRecord * * * * * * * * * // Chip Times record
{
* * time_t hiStartTime; * * * * * * * * * *// Start Time
// much more...} timeWork; * * * * * * * * * * *// entrant info records

typedef map<int, ChipRecordBCI;
* * * * BCI bci;
* * * * map<int, ChipRecord>::iterator bIter;

* * int * *nBib *= 17;
* * time_t cTime = 11151544;

// initialize and populate "timeWork" structure, etc.
* * bci.insert(bci::value_type(bibNumber, timeWork));
//...
// obtain a cTime value...
* * bIter = bci.find(nBib);
* * if(bIter != bci.end())
* * {
* * * * timeWork = bIter->second; * * * * * * *//???
* * * * timeWork = bci.find(nBib)->second; * * // ???
* * * * timeWork = (*bIter).second; * * * * * *// ???
* * * * if(cTime timeWork.hiStartTime) *// *use highest time
* * * * { * * * * * * * * * * * * * ** * // update the object
* * * * * * bIter->second.hiStartTime = cTime; // ???
* * * * * * timeWork.hiStartTime = cTime; * * *// ???
* * * * } *// if
* * } *// if

* *It's the code directly above that doesn't do what I intend: change
the map object's value and update the object. *There is much more going
on in the program, but this is the simplest amount that demonstrates the
issue. *I don't know how to update the object. *Please advise. *TIA
In your posted code you insert an element with the key bibNumber. But
then you find with the key nBib. The former is not defined in your
posted code.

Why not just do a simple program and print out some results or run it
through a debugger?

HTH
Nov 17 '08 #2
I'm having difficulty updating map objects. =A0In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.

struct ChipRecord = // Chip Times record
{
time_t hiStartTime; // Start Time
// much more...} timeWork; // entrant info records

typedef map<int, ChipRecordBCI;
BCI bci;
map<int, ChipRecord>::iterator bIter;

nBib = 17;
time_t cTime = 11151544;

// initialize and populate "timeWork" structure, etc.
bci.insert(bci::value_type(nBib, timeWork));
//...
// obtain a cTime value...
bIter =3D bci.find(nBib);
if(bIter !=3D bci.end())
{
timeWork = bIter->second; //???
timeWork = bci.find(nBib)->second; // ???
timeWork = (*bIter).second; // ???
if(cTime timeWork.hiStartTime) // use highest time
{ // update the object
bIter->second.hiStartTime = cTime; // ???
timeWork.hiStartTime = cTime; // ???
} // if
} // if

It's the code directly above that doesn't do what I intend: change
the map object's value and update the object. =A0There is much more going
on in the program, but this is the simplest amount that demonstrates the
issue. =A0I don't know how to update the object. =A0Please advise. TIA

In your posted code you insert an element with the key bibNumber. But
then you find with the key nBib. The former is not defined in your
posted code.
Yes, my apologies. I tried to post a simple segment of my program,
and I made that mistake.
Nevertheless, I still need help on this. I had hoped my code
explained the problem... 8<{{
Nov 17 '08 #3
I'm having difficulty updating map objects. =A0In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.

struct ChipRecord = // Chip Times record
{
time_t hiStartTime; // Start Time
// much more...} timeWork; // entrant info records

typedef map<int, ChipRecordBCI;
BCI bci;
map<int, ChipRecord>::iterator bIter;

nBib = 17;
time_t cTime = 11151544;

// initialize and populate "timeWork" structure, etc.
bci.insert(bci::value_type(nBib, timeWork));
//...
// obtain a cTime value...
bIter =3D bci.find(nBib);
if(bIter !=3D bci.end())
{
timeWork = bIter->second; //???
timeWork = bci.find(nBib)->second; // ???
timeWork = (*bIter).second; // ???
if(cTime timeWork.hiStartTime) // use highest time
{ // update the object
bIter->second.hiStartTime = cTime; // ???
timeWork.hiStartTime = cTime; // ???
} // if
} // if

It's the code directly above that doesn't do what I intend: change
the map object's value and update the object. =A0There is much more going
on in the program, but this is the simplest amount that demonstrates the
issue. =A0I don't know how to update the object. =A0Please advise. TIA

In your posted code you insert an element with the key bibNumber. But
then you find with the key nBib. The former is not defined in your
posted code.
Yes, my apologies. I tried to post a simple segment of my program,
and I made that mistake.
Nevertheless, I still need help on this. I had hoped my code
explained the problem... 8<{{
Nov 17 '08 #4
Mike Copeland schrieb:
I'm having difficulty updating map objects. In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.
What means "don't work" in your case? Didn't it compile? Does it give
you false results? Explain what is wrong with your approach and what the
expected result is.

Also, please provide a *compilable* minimal example, with main()
function and all the stuff.
struct ChipRecord // Chip Times record
{
time_t hiStartTime; // Start Time
// much more...
} timeWork; // entrant info records
typedef map<int, ChipRecordBCI;
BCI bci;
map<int, ChipRecord>::iterator bIter;

int nBib = 17;
time_t cTime = 11151544;

// initialize and populate "timeWork" structure, etc.
bci.insert(bci::value_type(bibNumber, timeWork));
//...
// obtain a cTime value...
bIter = bci.find(nBib);
It's better style to declare variables on first use. It's easier for the
reader of your program (co-workers, and in some weeks, yourself) to
understand the code:

BCI::iterator bIter = bci.find(nBib);
if(bIter != bci.end())
{
timeWork = bIter->second; // ???
Same here:
ChipRecord timeWork = bIter->second;

Note: This makes a copy of the object in the map. Changing timeWork only
changes this copy. If you want to modify the object inplace, take a
reference.

// pick a better name for the variable, too
ChipRecord& timeWork = bIter->second;

Changes to 'timeWork' will directly alter the object in the map.
timeWork = bci.find(nBib)->second; // ???
timeWork = (*bIter).second; // ???
(*bIter).second and bIter->second are the same.
if(cTime timeWork.hiStartTime) // use highest time
{ // update the object
bIter->second.hiStartTime = cTime; // ???
timeWork.hiStartTime = cTime; // ???
} // if
} // if

It's the code directly above that doesn't do what I intend: change
the map object's value and update the object. There is much more going
on in the program, but this is the simplest amount that demonstrates the
issue. I don't know how to update the object. Please advise. TIA
--
Thomas
Nov 17 '08 #5
mr*****@cox.net (Mike Copeland) kirjutas:
I'm having difficulty updating map objects. In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.
[...]
map<int, ChipRecord>::iterator bIter;
[...]
bIter = bci.find(nBib);
if(bIter != bci.end())
{
[...]
bIter->second.hiStartTime = cTime; // ???
This seems to be basically correct, so your error is probably elsewhere.
Try to prepare a compilable short example of the problem; during this you
will probably find the cause of the problem; if not, post here again!

hth
Paavo

Nov 17 '08 #6

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

Similar topics

1
by: john smith | last post by:
Hi, I have a question about map and classes that contain maps. My problem is declaring any class methods const that would do something to the map. Presumably it's because when operator is...
11
by: Markus Hämmerli | last post by:
I have seen in the STL that the map is working with one key. Does everyboby know if there is a possibility to have two key. Do you have a little example. Thanks Markus
1
by: Florian Liefers | last post by:
"Hello World\n", i have the following problem: One of my headerfiles for a lib is including <vector>. When i compile the lib, everything is done well. In my application another file is...
8
by: Pierre Couderc | last post by:
I am looking for a "special" kind of map : - it is read like a map - if the searched element exists, it is given back imediately - if the searched element does not exist, an initialise() is...
14
by: laurence | last post by:
I am implementing a comprehensive image-map generator utility, so have been studying W3C HTML 4.01 Specification (http://www.w3.org/TR/html4/struct/objects.html#h-13.6) on image maps (among other...
3
by: Evgeny | last post by:
Hi, all! I didn't find yet solution for this problem! Somebody knows where is a catch? Looks like "operator =" or copy constructor not implemented in one of internal templates.... Thanks in...
13
by: Steve Edwards | last post by:
Hi, Given a map: typedef map<long, string, greater<long> > mapOfFreq; Is there a quicker way to find the rank (i.e. index) of the elememt that has the long value of x? At the moment I'm...
6
by: helpneeded | last post by:
Hi I am a novice using the <maptag. I have a question. I would really appreciate if you could answer me. I want to use the <maptag to dynamically update my map with coordinates. These...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.