0

i am trying to make a system of container classes that can be used with a data loader class to load data from text files

here are the two classes of data:

class Customer
{
    //...
};

class Tour
{
    //...
};

these are my two container classes:

<template T>
class P_VContainer
{
    boost::ptr_vector<T> data;
    //...
};

<template T>
class ListContainer
{
    std::list<T> data;
    //...
};

and finally my data loader template:

<template T>
class DataLoader
{
    T<Customer> custList;
    T<Tour> tourList;

    //...
};

i have overloaded the >> operator in Customer and Tour so that an ifstream can be passed to them, a line is taken from the stream, tokenised and put it into the object instance variables.

the container classes handle the insertion in order and the data loader manages the lists and creates the ifstream so that it can be passed to the objects.

so my first question --SOLVED-- is how can i make my DataLoader class work so that i can initialise it in main by:

DataLoader<P_VContainer> loader;

and then it instantiates the following instance variables automatically:

P_VContainer<Customer> custList;
P_VContainer<Tour> tourList;

or is that even possible?

and my second problem --UNSOLVED-- is this:

i am loading my customers file in first, and populating that list.

after that i have to load in the tours, which have customerIDs for the customers that booked them, and i want to store those customers in a vector of pointers in each of the tour objects so that the customer information is easily accessible.

at the moment i am storing the customerIDs as a list of strings, then when the tours are all loaded, passing custList into a function that searches through custList, matching it with the list of strings

this means i am having to maintain two lists, one of strings and the other pointers, and basically double handle all the data.. considering the datasets are quite large, this means a lot longer in loading time..

so i was wondering if there is a way that i can access the custList instance variable from inside the overloaded >> operator for Tour and generate the list of pointers as i create the Tour objects?

technically everything is occurring inside the scope of the DataLoader class, so i think it should be possible, but im just not too sure how to go about it.. maybe make it a friend class? i have tried doing that but havent had any luck so far..

any help would be greatly appreciated, and sorry for the long winded explanation, hopefully it made sense..

guskenny83
  • 1,321
  • 14
  • 27
  • Your class template declarations contain some syntax errors. – dyp Oct 19 '13 at 18:11
  • "and then it instantiates the following instance variables automatically:" There are template *template-parameters*. – dyp Oct 19 '13 at 18:12
  • sorry, could you elaborate on that please? i know that there are syntax errors with my DataLoader class, because it doesnt work at the moment.. what is the correct way to make a template of a template? – guskenny83 Oct 19 '13 at 18:19
  • 1
    First it's probably just a typo, but ` – dyp Oct 19 '13 at 18:20
  • thanks so much, you were right, the first one was a typo; but the DataLoader one worked! – guskenny83 Oct 19 '13 at 18:27
  • do you have any insight into my second question at all? – guskenny83 Oct 19 '13 at 18:28
  • Can you make an [SSCCE](http://sscce.org) for the second question? As those two issues are rather unrelated, you could split them into two StackOverflow question. – dyp Oct 19 '13 at 18:49
  • done, http://stackoverflow.com/questions/19469878/accessing-instance-variable-from-another-template-class thanks again for your help – guskenny83 Oct 19 '13 at 19:04

0 Answers0