I have project that is passing around a lot of path, file, and stream arguments.
So maybe a struct vector can contain all that information, and reference the vector where ever a path argument is needed.
1 2 3 4 5 6 7 8 9
struct Path
{
const std::string path;
const std::string file;
const std::iostream& stream;
};
std::vector<Path> vPaths;
//vPaths is initialized in the constructor
//example usage: vPaths[4].stream
Is there a name for this sort of thing so I can find a pattern or example?
Or is vPaths a bad idea?
Whenever you have a set of related variables a structure of a class can be considered, however watch out about creating a "bunch" of open stream instances since there may be limitations on the number of allowed open files on your system. And what happens if opening one or several of the streams fails, how and where are you going to handle the error.
Why do need to pass both the strings containing the paths and file names along with the stream instances. Perhaps you should just be passing one or the other into your functions?
I know it is just an example, but why the const qualifications? And why the stream reference?
Then make them private and only allow the constructors to modify the values.
That's how I have been defining ofstreams in functions.
But that's not how you should be defining them in your class. The streams in your class should be normal, non-const and non-reference instances. By the way in your functions you really should be passing things like std::string by reference/const reference because copying can be quite expensive when using non-POD types.
By the way you really didn't answer one of the more important questions:
And what happens if opening one or several of the streams fails, how and where are you going to handle the error.