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

vector by name, recordset/field setup

I need to dynamically add (but not remove) vectors of doubles based on
keys/names. Please see my code below. Am I reinventing the wheel or doing
anything inefficiently? I get the feeling that I am, just not sure:

#include "stdafx.h"
#include <vector>

using namespace std;

typedef vector<double> field;
vector<field> recordset;
vector<const char*> names;
int m_RecordCount;
// Clears the recordset and "names" array
// then sets the recordset size (used in AddField).
void ResetRecordset(int RecordCount)
{
recordset.clear();
names.clear();
m_RecordCount = RecordCount;
}

// Adds a new field to the recordset
void AddField( char* Name)
{
field f;
f.resize(m_RecordCount);
recordset.push_back(f);
names.push_back(Name); // The associated key or name for this field
}

// Returns a field by name lookup. I suppose a map would be faster but I
only have around 10 fields.
const field GetField(const char* Name)
{
field ret;
for(int n = 0; n != names.size(); ++n)
if(strcmp(names[n],Name) == 0)
return recordset[n];

return ret;
}

int main(int argc, char* argv[])
{

ResetRecordset(100); // Size for all fields.
AddField("Test");

field f = GetField("Test");
if(f.size() > 1)
f[0] = 123456.789;

return 0;
}
Aug 13 '05 #1
1 2513
Richard wrote:
I need to dynamically add (but not remove) vectors of doubles based on
keys/names. Please see my code below. Am I reinventing the wheel or
doing anything inefficiently? I get the feeling that I am, just not
sure:

#include "stdafx.h"
#include <vector>

using namespace std;

typedef vector<double> field;
vector<field> recordset;
vector<const char*> names;
int m_RecordCount;


You should probably look at the possibility to use

std::map<std::string, field> recordset;

instead of separate 'names' and 'm_RecordCount' objects. BTW, you
can always request the count from the vector, can't you? Just call
recordset.size().

V
Aug 13 '05 #2

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

Similar topics

1
by: Jenny Kurniawan | last post by:
I have a procedure that goes like this: Private Sub Form_Current() Dim strSQL1 As String strSQL1 = "Select Price_Year_Name from Price_Year where Category_ID = 1 And By_Default <> 0" ' I...
0
by: gary artim | last post by:
Hi All, I have a problem using DBIx::RecordSet. I get correct results but continue to get these messages on stderr. I looked at Compat.pm and it seems to be pointing out a problem with my call...
5
by: J. Muenchbourg | last post by:
The field name 'articleid', which is an identity/primary key , is not being recognized in my recordset as I get an " Item cannot be found in the collection corresponding to the requested name or...
35
by: Ram Laxman | last post by:
I have used vector in the VC++ compiler. I have included #include <string> #include <algorithm> #include <vector> std::vector<int> field; std::vector <int>::size_type i;
1
by: Michael | last post by:
Ok guys I have the following: class glVertexArray { public: string name }; class glSurfaceLibrary {
2
by: mkjets | last post by:
I would be grateful if someone could give me a direction in solving this problem. Here is the simplified setup for the code that I am trying to run in an Access form. STRFLD is an array that I...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
1
by: kccoolrocks1981 | last post by:
I need to create a temporary table in VBA Code but recordset.fields(i).Type gives me an integer value instead of the required field's Type. For an example Field_Name= "CriteriaName" and it's...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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,...
0
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...

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.