I've got an STL class (see below) with two functions to store and
retrieve data - msg structs.
The "Store" function when called will copy the received message
(depending on which message) into the appropriate array. For instance
if I receive a RCVD_MSG1, I'll copy into msg1 [ 0 ]. Upon receipt of
the next RCVD_MSG1. I'll copy into msg1 [ 1 ].
The Retrieve function when called should retrieve the latest copy.
ie. msg1 [ 0 ] or msg1 [ 1 ].
I've made it this far and am unsure how best to implement this.
One other thing. I suspect maps (not too familiar with maps but I
vaguely recall seeing something similiar in a newsgroup recently .. )
would be provide an more elegant approach but i'm unsure how to modify
code to do this.
Thanks
------------------
#include <iostream.h>
const Max = 20;
const True = 1;
const False = 0;
struct {
unsigned rcvd_item1 : 16;
unsigned rcvd_item2 : 13;
unsigned rcvd_item3 : 10;
unsigned spare : 9;
} RCVD_MSG1;
struct {
unsigned rcvd_item1 : 11;
unsigned rcvd_item2 : 10;
unsigned spare : 11;
} RCVD_MSG2;
RCVD_MSG2 msg2 [ 2 ];
RCVD_MSG1 msg1 [ 2 ];
template<class T> class Vector
{
struct
{
T Data; //field Data is type T ..
// May need to make this T Data [ 2 ];
int Defined; //field Defined is type int
} Elements[Max]; //array of Max items
public:
Vector::Vector()
//Creates an empty abstract array.
{
int Index;
for (Index = 0; Index < Max; ++Index)
Elements[Index].Defined = False;
}
void Vector::Init(T X)
//Initialize all elements to X
//Pre : Vector created and X defined.
//Post: All elements set to X and marked as defined.
{
int Index;
for (Index = 0; Index < Max; ++Index)
{
Elements[Index].Data = X;
Elements[Index].Defined = True;
}
}
void Vector::Store (T X, int I)
//Stores X at position I in abstract array.
//Pre : Vector created; X and I are defined.
//Post: Elements[Index].Data is X and position I is defined.
//Need to implement ping/pong approach of the stored sturcts.
// i.e. first call to Store a RCVD_MSG1 would store at msg1 [ 0 ]
// Next call would store at msg1 [ 1 ]
{
Elements[i].Data = X;
Elements[i].Defined = True;
}
void Vector::Retrieve(T &X, int I, int &Success)
//Copies the value stored at vector position I to X.
//
//Post: Returns value stored at position I through X and
// set Success to True, if position defined; otherwise
// Success set to False.
// Retrieve the LATEST at all times .. msg1 [ 0 ] or msg1 [ 1 ];
{
Success = Elements[i].Defined;
if (Success)
X = Elements[i].Data;
}
}; 2 3717
I have read priority_queue is good for this type of operation.
"forums_mp" <fo********@bellsouth.net> wrote in message
news:c9**************************@posting.google.c om... I've got an STL class (see below) with two functions to store and retrieve data - msg structs.
The "Store" function when called will copy the received message (depending on which message) into the appropriate array. For instance if I receive a RCVD_MSG1, I'll copy into msg1 [ 0 ]. Upon receipt of the next RCVD_MSG1. I'll copy into msg1 [ 1 ]. The Retrieve function when called should retrieve the latest copy. ie. msg1 [ 0 ] or msg1 [ 1 ].
I've made it this far and am unsure how best to implement this. One other thing. I suspect maps (not too familiar with maps but I vaguely recall seeing something similiar in a newsgroup recently .. ) would be provide an more elegant approach but i'm unsure how to modify code to do this.
Thanks
------------------
#include <iostream.h>
const Max = 20; const True = 1; const False = 0;
struct { unsigned rcvd_item1 : 16; unsigned rcvd_item2 : 13; unsigned rcvd_item3 : 10; unsigned spare : 9; } RCVD_MSG1;
struct { unsigned rcvd_item1 : 11; unsigned rcvd_item2 : 10; unsigned spare : 11; } RCVD_MSG2;
RCVD_MSG2 msg2 [ 2 ]; RCVD_MSG1 msg1 [ 2 ];
template<class T> class Vector { struct { T Data; //field Data is type T .. // May need to make this T Data [ 2 ];
int Defined; //field Defined is type int } Elements[Max]; //array of Max items
public: Vector::Vector() //Creates an empty abstract array. { int Index;
for (Index = 0; Index < Max; ++Index) Elements[Index].Defined = False; }
void Vector::Init(T X) //Initialize all elements to X //Pre : Vector created and X defined. //Post: All elements set to X and marked as defined. { int Index;
for (Index = 0; Index < Max; ++Index) { Elements[Index].Data = X; Elements[Index].Defined = True; } }
void Vector::Store (T X, int I) //Stores X at position I in abstract array. //Pre : Vector created; X and I are defined. //Post: Elements[Index].Data is X and position I is defined. //Need to implement ping/pong approach of the stored sturcts. // i.e. first call to Store a RCVD_MSG1 would store at msg1 [ 0 ] // Next call would store at msg1 [ 1 ] { Elements[i].Data = X; Elements[i].Defined = True; }
void Vector::Retrieve(T &X, int I, int &Success) //Copies the value stored at vector position I to X. // //Post: Returns value stored at position I through X and // set Success to True, if position defined; otherwise // Success set to False. // Retrieve the LATEST at all times .. msg1 [ 0 ] or msg1 [ 1 ];
{ Success = Elements[i].Defined; if (Success) X = Elements[i].Data; }
};
"forums_mp" <fo********@bellsouth.net> wrote in message
news:c9**************************@posting.google.c om... I've got an STL class (see below) with two functions to store and retrieve data - msg structs.
The "Store" function when called will copy the received message (depending on which message) into the appropriate array. For instance if I receive a RCVD_MSG1, I'll copy into msg1 [ 0 ]. Upon receipt of the next RCVD_MSG1. I'll copy into msg1 [ 1 ]. The Retrieve function when called should retrieve the latest copy. ie. msg1 [ 0 ] or msg1 [ 1 ].
I've made it this far and am unsure how best to implement this. One other thing. I suspect maps (not too familiar with maps but I vaguely recall seeing something similiar in a newsgroup recently .. ) would be provide an more elegant approach but i'm unsure how to modify code to do this.
Thanks
------------------
#include <iostream.h>
const Max = 20; const True = 1; const False = 0;
struct { unsigned rcvd_item1 : 16; unsigned rcvd_item2 : 13; unsigned rcvd_item3 : 10; unsigned spare : 9; } RCVD_MSG1;
struct { unsigned rcvd_item1 : 11; unsigned rcvd_item2 : 10; unsigned spare : 11; } RCVD_MSG2;
RCVD_MSG2 msg2 [ 2 ]; RCVD_MSG1 msg1 [ 2 ];
template<class T> class Vector { struct { T Data; //field Data is type T .. // May need to make this T Data [ 2 ];
int Defined; //field Defined is type int } Elements[Max]; //array of Max items
public: Vector::Vector() //Creates an empty abstract array. { int Index;
for (Index = 0; Index < Max; ++Index) Elements[Index].Defined = False; }
void Vector::Init(T X) //Initialize all elements to X //Pre : Vector created and X defined. //Post: All elements set to X and marked as defined. { int Index;
for (Index = 0; Index < Max; ++Index) { Elements[Index].Data = X; Elements[Index].Defined = True; } }
void Vector::Store (T X, int I) //Stores X at position I in abstract array. //Pre : Vector created; X and I are defined. //Post: Elements[Index].Data is X and position I is defined. //Need to implement ping/pong approach of the stored sturcts. // i.e. first call to Store a RCVD_MSG1 would store at msg1 [ 0 ] // Next call would store at msg1 [ 1 ] { Elements[i].Data = X; Elements[i].Defined = True; }
void Vector::Retrieve(T &X, int I, int &Success) //Copies the value stored at vector position I to X. // //Post: Returns value stored at position I through X and // set Success to True, if position defined; otherwise // Success set to False. // Retrieve the LATEST at all times .. msg1 [ 0 ] or msg1 [ 1 ];
{ Success = Elements[i].Defined; if (Success) X = Elements[i].Data; }
};
I don't see how a map would help. I think you could do everything you need
with std::vector:
#include <vector>
#include <exception>
template <typename RCVD_MSG>
class messages
{
private:
std::vector<RCVD_MSG> m_vec;
public:
void store(RCVD_MSG msg)
{
m_vvec.push_back(msg);
}
RCVD_MSG retrieve()
{
if (m_vec.size() == 0)
throw std::exception("oops");
return m_vec.back();
}
int size() const // check this before calling retrieve to avoid
exceptions
{
return m_vec.size();
}
};
messages<RCVD_MSG1> m1;
messages<RCVD_MSG2> m2;
<untested code>
--
Cy http://home.rochester.rr.com/cyhome/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Craig Storey |
last post by:
I have a little php application to store day hiking trips and to keep a
running total of their yearly trips for a few users. Currently they
select their hiking routes using drop lists or...
|
by: Mark P |
last post by:
I wrote some code which makes heavy use of std::map. In fact, for a
typical instance, I may have on the order of 100K maps, each with only a
small number of elements.
(In case you're curious,...
|
by: Brian |
last post by:
Hello.
I want to store some system settings in XML, but I am new to it. So
far, I am able to retrieve the attributes, but not the elements they
belong to (I hope my terminology is right). For...
|
by: James Geurts |
last post by:
This is probably more of an ASP.Net situation rather than
c#, but since all of my code behind is in c#, maybe it
fits here. I'm wondering, generally, at what point is it
too inefficient to store...
|
by: Mark |
last post by:
I am attempting to build a repeating list using a repeater control. I want
to add a checkbox to each item (line) and 'Select All' and 'Clear All'
buttons.
I have figured out how to do this...
|
by: jsale |
last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the...
|
by: utab |
last post by:
Dear all,
I am trying to create a look-up table for a text search and replacement
class which will be used with a commercial software(MCS NASTRAN, I
guess you may have heard that before ).
I...
|
by: Alan T |
last post by:
Currently our SQL Server 2000 database table field is using char to store as
boolean, ie. "T" or "F".
Now we change the field from char to bit field. I am not sure how it has
impact on the C#...
|
by: mwebel |
last post by:
Hi,
i had this problem before (posted here and solved it then) now i have
the same problem but more complicated and general...
basically i want to store the adress of a istream in a char* among...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
| |