I am working on a small columns class, since I use allot of tabular data. I am trying to set up code to allow me to efficiently read in tabular data, manipulate it, and write to output files. I more or less know what I need to do, but there are many options to sort through.
I have the beginnings of a columns class, without access functions and such. This also includes a vector of class that will hold one object for each col.
There is some meta data here (like the content field), that will probably end up in a different class. I have vectors for the different data types that could be in the data. Only one of these would get populated, depending on the value of "type".
I am reading all of the data and storing each row in a vector of string,
Code:
// create an input stream and open the input file
ifstream splitsInput;
splitsInput.open( splitsInFile.c_str() );
// read in each line
while(getline(splitsInput,newSplitsLine)) {
// remove '\r' EOL chars
newSplitsLine.erase (remove(newSplitsLine.begin(),newSplitsLine.end(),'\r') , newSplitsLine.end());
// store row data in vector of string
storeSplitsRows.push_back(newSplitsLine);
}
Then I can create an object for each col by parsing the first row,
Code:
colsRowStream << storeSplitsRows[0];
int i = 0;
// parse header row into cells, tab delimiter
while(getline(colsRowStream,rowCell,'\t')) {
// create new column data object
column_data newCol;
// add to vector
columns.push_back(newCol);
i++;
}
// clear the buffer
colsRowStream.clear();
Now I have an object for each col and can begin processing the other rows.
I would like to make processing a function where I would add a row to the string stream, select a target variable in the class for the parsed data to go, and pass the stringstream and the target to a loading function.
Code:
// accepts a string stream and parses the data in to columns
int row_toCols(stringstream colsRowStream){
int i = 0;
std::string rowCell
// parse row into cells by tab delimiter
while(getline(colsRowStream,rowCell,'\t')) {
columns[i].content = rowCell;
i++;
}
// clear the buffer
colsRowStream.clear();
}
// load first row into string stream
colsRowStream << storeSplitsRows[0];
row_toCols( stringstream colsRowStream);
The code above results in the data in the first row being parsed by tab and deposited in the content string var of each object. What I need to do is to be able to pass the target in the call so I can re-use this function to populate the rest of the data structure. I guess I would set the function to look for a pointer to an object, and then pass the object using the & operator, but there are always allot of ways of doing this kind of thing, so I'm not sure. I also need the code to handle different data types other than string. I could have different loading functions for different data types if that is necessary.
If I am going about this whole thing in the wrong way, now would be a good time to say so. The loading function will probably be a class method at some point.
Is it possible to view all the functions exported by a given object file?
"dump -tv" comes the closest, but what exactly am I looking for to determine whether the symbol exists in the object file?
Essentially, I have a library that requires a call to "xdr_sizeof" and the compile is failing... (5 Replies)
Hi,
I have a base class and derived a class from the base class, i want to print & read the data for the object created for the derived class,so i have overloaded both the << and >> operators and also have done the foward declaration.
Below is the code snippet,
#include <iostream>
class... (3 Replies)
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)
Hello,
i am using the sigaction function to handle the SIGCHLD signal.Is it possible to use a class member function as the handler function (the sa_handler member of the sigaction structure)?
The function's signature is:
void (*sa_handler)(int);so i don't think i can use a static member function... (2 Replies)
Hi,
Anybody know any way to Call with Shell Script an external function wrote in .C or .So (Shared Object) on AIX enviroment and returning parameters of .C or .SO to Shell Script?
Tks!! (6 Replies)
I have a code as following:
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
//the class Nth is a predicates
class Nth{
private:
int nth;
int count;
public:
Nth(int n):nth(n),count(0){}
bool operator()(int){
... (2 Replies)
we have 2.2.0 of opends running on RedHat 2.6.21 and we're trying to setup a structure that will suit our needs. One of the things we'd like to do is create our own custom object classes based off some of the existing ones you get out of the box. The opends documentation covers this here (sorry, it... (1 Reply)
I have a class called Parsing with the following function. I want to create a wrapper for it, so that I call it using GetReal rather than GetFloat.
Bit confused on how to do this.
class Parsing {
private:
int Length; //
int Ptr; ... (3 Replies)
How to initialize an object of class say "A", with an object of type say "B".
The following code give the error message "error: conversion from âAâ to non-scalar type âBâ requested"
#include <iostream>
using namespace std;
class B;
class A{
public:
A() { cout <<"\nA()" << endl; }
... (1 Reply)
Hello All,
I am a learner in C++. I was testing my inheritance knowledge with following piece of code.
#include <iostream>
using namespace std;
class base
{
public :
void display()
{
cout << "In base display()" << endl;
}
void display(int k)
{... (2 Replies)