473,795 Members | 2,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to build string buffer table from std::list and structs

14 New Member
Hi,
I'm having the following structures and std::list of that structs.

I need to read the list of list as below and build a buffer as a table information.
Any idea on how to build a table info (string buffer).

list<NVPairsWit hId> m_ResponseObj;

struct NVPairsWithId
{
string m_id;
list<NVObject> m_NVPairs;
};

struct NVObject
{
string m_name;
string m_value;
};

This is how the data in it will be, (kind of each and every row information)
m_id=100
m_name=c1, m_name=c2
m_value=r1, m_value=r1

m_id=200
m_name=c1, m_name=c2
m_value=r2, m_value=r2

This, I need to traverse the list of list and build the buffer as
id c1 c2
100 r1 r1
200 r2 r2

Please help me out on this.
Thanks
Dec 6 '07 #1
5 2043
weaknessforcats
9,208 Recognized Expert Moderator Expert
If your buffer has to have entries like:

id c1 c2


why not just use:
Expand|Select|Wrap|Line Numbers
  1. struct Data
  2. {
  3.    string id;
  4.    string name;
  5.    string value;
  6. };
  7.  
and then just have a list<Data> ??
Dec 6 '07 #2
rsennat
14 New Member
It's not like that. For a single id, there could be multiple sets of names and values. here for id=100, {name = c1, value = r1}, {name = c2, value = r1}.
so it goes like that....

id c1 c2
------------
100 r1 r1
200 r2 r2

Any idea how can i build this..
thanks

If your buffer has to have entries like:

id c1 c2


why not just use:
Expand|Select|Wrap|Line Numbers
  1. struct Data
  2. {
  3.    string id;
  4.    string name;
  5.    string value;
  6. };
  7.  
and then just have a list<Data> ??
Dec 6 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
id=100, {name = c1, value = r1}, {name = c2, value = r1}.
I see.

Then in that case your approach will work:
list<NVPairsWit hId> m_ResponseObj;

struct NVPairsWithId
{
string m_id;
list<NVObject> m_NVPairs;
};

struct NVObject
{
string m_name;
string m_value;
};
Expand|Select|Wrap|Line Numbers
  1. list<NVPairsWithId> m_ResponseObj;
  2. NVPairsWithId id100;
  3. id100.m_id = 100;
  4. m_ResponseObj.puch_back(id100);
  5.  
That gets the ids in m_ResponseObj.

Then to add a name/value pair you will need to traverse m_ResponseObj looking for the element whose m_id is, say 100, then you add the name/value pair to that element:
Expand|Select|Wrap|Line Numbers
  1. NVPairsWithId* ptr = FindMyId(100); //detail of searxch omitted
  2. NVObject data;
  3. data.name = "Ralph";
  4. data.value = "45";
  5. ptr->m_NVPairs.push_back(data);
  6.  
More or less. I didn't compile or test this code.

Lastly, avoid naming conventions, like m_, for your variables. A member variable is this->name. The compiler can't check that everyone is using m_. Microsoft started this by having C programmers write C++.
Dec 6 '07 #4
rsennat
14 New Member
That's the way I'm doing it for putting the data into this.
But I would like to read the data back from it to build the string buffer table (tabular format).

Thanks

I see.

Then in that case your approach will work:


Expand|Select|Wrap|Line Numbers
  1. list<NVPairsWithId> m_ResponseObj;
  2. NVPairsWithId id100;
  3. id100.m_id = 100;
  4. m_ResponseObj.puch_back(id100);
  5.  
That gets the ids in m_ResponseObj.

Then to add a name/value pair you will need to traverse m_ResponseObj looking for the element whose m_id is, say 100, then you add the name/value pair to that element:
Expand|Select|Wrap|Line Numbers
  1. NVPairsWithId* ptr = FindMyId(100); //detail of searxch omitted
  2. NVObject data;
  3. data.name = "Ralph";
  4. data.value = "45";
  5. ptr->m_NVPairs.push_back(data);
  6.  
More or less. I didn't compile or test this code.

Lastly, avoid naming conventions, like m_, for your variables. A member variable is this->name. The compiler can't check that everyone is using m_. Microsoft started this by having C programmers write C++.
Dec 6 '07 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
I would think you could iterate m_ResponseObj and for each element you traverse m_NVPairs.

When you reach the end of m_NVPairs, you advance to the next element of m_ResponseObj. When you reach the end of m_ResponeObj, you are done.

The display format should be easy.
Dec 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2849
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl list class must Ioverride in order for this to work?
5
1790
by: Eric Lilja | last post by:
Hello, consider this complete program (sorry, it's not minimal but I hope it's readable at least): #include <algorithm> #include <iostream> #include <vector> class Row { public:
3
2144
by: Jef Driesen | last post by:
The number of items in my std::list is changed after sorting (using std::list member function sort). I'm using MSVC6 and the actual (pseudo) code is posted below. The output from size() is different before and after the sort. If I remove the sorting (and nothing else), both numbers remain the same. int nmerged = 0; do { std::list<mum_pair> mregions;
6
6663
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't give me this capability. So I want std::list<T*>::iterator. However, the container is of type std::list<T*>. How to get std::list<const T*>::iterator?
44
3884
by: Josh Mcfarlane | last post by:
Just out of curiosity: When would using std::list be more efficient / effective than using other containers such as vector, deque, etc? As far as I'm aware, list doesn't appear to be specialized for anything. Thanks, Josh McFarlane
7
2981
by: alex221 | last post by:
In need to implement a tree structure in which every node has arbitrary number of children the following code has come into mind: using std::list; template < class Contents class Tree_node{ Contents cn; list < BTree_node < Contents children; ........
15
4162
by: desktop | last post by:
If I have a sorted std::list with 1.000.000 elements it takes 1.000.000 operations to find element with value = 1.000.000 (need to iterator through the whole list). In comparison, if I have a std::set with 1.000.000 element it will only take approx lg 1.000.000 = 20 operations! Can it really be true that the difference is a factor of 1.000.000/20 = 50.000 in this case?
8
3427
by: Spoon | last post by:
Hello, Could someone explain why the following code is illegal? (I'm trying to use a list of (C-style) arrays.) #include <list> typedef std::list < int foo_t; int main() { int v = { 12, 34 };
12
2714
by: isliguezze | last post by:
template <class T> class List { public: List(); List(const List&); List(int, const T&); void push_back(const T &); void push_front(const T &); void pop_back();
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
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
10165
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
10002
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
9044
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
7543
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
6783
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();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.