Sponsored Content
Top Forums Programming passing object to function, columns class Post 302513284 by LMHmedchem on Tuesday 12th of April 2011 07:00:21 PM
Old 04-12-2011
I have made some progress, I will deal with the issue of using string or stringstream in a little bit. Can a string be parsed by a delimiter using the same method I was using for stringstream, or do I have to do something different?

I have the function creating the objects,
Code:
// creates a data object and meta data object for each column
int createColObjs( stringstream &colsRowStream ){
   std::string rowCell;
   // parse header row into cells, tab delimiter
   while(getline(colsRowStream,rowCell,'\t')) {
      // create new column data object
      col_metadata newColMeta;  metadata.push_back(newColMeta);
      // create new column data object
      column_data newCol;  columns.push_back(newCol);
   }
   // clear the buffer
   colsRowStream.clear();
}

This is called with,
colsRowStream << storeSplitsRows[0];
createColObjs ( colsRowStream );

which dumps the first row into the stream and passes it to the create object function. I get a col metadata object and a col data object for each col in the input file. The objects are stored in vectors, metadata and columns respectively.

I am a bit stuck on the loading function, which parses the stream and loads it to the appropriate var in the col object.
Code:
// accepts a stringstream and parses the data in to columns
int metadata_row_toCol( stringstream &colsRowStream, 
                        std::vector<col_metadata>& metadata ){
   int i = 0;
   std::string rowCell;
   // parse row into cells, tab delimiter
   while(getline(colsRowStream,rowCell,'\t')) {
      metadata[i].content = rowCell;
      i++;
   }
   // clear the buffer
   colsRowStream.clear();
}

This above works, but is hard coded to put the data into metadata[i].content. I can't seem to see how I indicate that the first rows goes into content, but the next row goes into a different member. It seems like I should be passing a pointer to metadata[i].content, and not to the metadata vector of objects.If I did that, I could pass a pointer to metadata[i].type for the next row, etc. All the function would need to know is that it is expecting a pointer to a class variable. At any rate, I need to be able to tell the loading function where to put the data that is parsed out of the stream, but I can't seem to work out the syntax.

LMHmedchem

Last edited by LMHmedchem; 04-12-2011 at 08:13 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

Listing function exports from object file

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)
Discussion started by: DreamWarrior
5 Replies

2. Programming

How to make a function friend to both base and derived class

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)
Discussion started by: ennstate
3 Replies

3. Shell Programming and Scripting

Passing global variable to a function which is called by another function

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)
Discussion started by: sars
4 Replies

4. Programming

Handling a signal with a class member function

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)
Discussion started by: Zipi
2 Replies

5. Shell Programming and Scripting

How to Call external function in .C or .So (Shared Object)

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)
Discussion started by: rdgsantos
6 Replies

6. Programming

question about function object

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)
Discussion started by: homeboy
2 Replies

7. UNIX and Linux Applications

opends- help with custom object class

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)
Discussion started by: snafu
1 Replies

8. Programming

Created a wrapper for a function in a class.

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)
Discussion started by: kristinu
3 Replies

9. Programming

How to initialize an object with another object of different class?

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)
Discussion started by: techmonk
1 Replies

10. Programming

C++ : Base class member function not accessible from derived class

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)
Discussion started by: anand.shah
2 Replies
FBSQL_FETCH_FIELD(3)							 1						      FBSQL_FETCH_FIELD(3)

fbsql_fetch_field - Get column information from a result and return as an object

SYNOPSIS
object fbsql_fetch_field (resource $result, [int $field_offset]) DESCRIPTION
Used in order to obtain information about fields in a certain query result. PARAMETERS
o $ result -A result identifier returned by fbsql_query(3) or fbsql_db_query(3). o $field_offset - The numerical offset of the field. The field index starts at 0. If not specified, the next field that wasn't yet retrieved by fbsql_fetch_field(3) is retrieved. RETURN VALUES
Returns an object containing field information, or FALSE on errors. The properties of the object are: o name - column name o table - name of the table the column belongs to o max_length - maximum length of the column o not_null - 1 if the column cannot be NULL o type - the type of the column EXAMPLES
Example #1 fbsql_fetch_field(3) example <?php fbsql_connect($host, $user, $password) or die("Could not connect"); $result = fbsql_db_query("database", "select * from table") or die("Query failed"); # get column metadata $i = 0; while ($i < fbsql_num_fields($result)) { echo "Information for column $i:<br /> "; $meta = fbsql_fetch_field($result); if (!$meta) { echo "No information available<br /> "; } echo "<pre> max_length: $meta->max_length name: $meta->name not_null: $meta->not_null table: $meta->table type: $meta->type </pre>"; $i++; } fbsql_free_result($result); ?> SEE ALSO
fbsql_field_seek(3). PHP Documentation Group FBSQL_FETCH_FIELD(3)
All times are GMT -4. The time now is 10:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy