how to initiate vector & fill values

I am using C++03 on Windows.

I am making program where I parse command line parameters. I created object where I want to save some informations from the command line like sourcefile, destination file (assuming that there can be more sources and more destinations).

In header file I have Src class
1
2
3
4
5
6
7
8
9
10
class Src {  
public:
  struct RGB { int r; int g; int b; } rgb;
  struct HSV { float h; float s; float v; } hsv;
  struct STAT { float min; float max; } stat;
  struct OPTIONS { HSV from; HSV to; RGB replace; };
  std::string file; // source file
  _BITMAP bitmap;
};


Target class
1
2
3
4
5
6
7
8
9
class Target {  
public:
  struct RGB { int r; int g; int b; } rgb;
  struct HSV { float h; float s; float v; } hsv;
  struct STAT { float min; float max; } stat;
  struct OPTIONS { HSV from; HSV to; RGB replace; };
  std::string file; // destination file
  _BITMAP bitmap;
};


And main class:
class MyClass{
private:
std::vector<Src*> sources;
std::vector<Target*> destination;
int actualSource;
int actualTarget;
public:
MyClass(int argc, char* argv[]);
};

In the main script I create the instance of main MyClass
1
2
3
4
int main(int argc, char* argv[])
{
MyClass Obj(argc, argv);
}


The implementation of the MyClass is in main file too:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
MyClass::MyClass(int argc, char* argv[]){
		int actualSource;
		int actualTarget;
		std::string arg;
        std::vector<std::string> raw_args( argv+1, argv+argc ) ;
		int i = 0;
		
		for (std::vector<std::string>::iterator it = raw_args.begin(); it != raw_args.end(); ++it)
        {
			i++;
			arg=(*it);
			std::cout << ": raw: " + arg + "\n";
			if (i == 0){
// HERE I WOULD LIKE TO INSERT new instance of Src class but I am not sure how to fill the values to the instance. Should I first create new element of MyClass::sources, fill the values and then to add the element here as the second argument?
MyClass::sources.insert(MyClass::sources.begin,  ... );
				}
			else if if (i == 1){
				}
			std::istringstream ss(arg);
			std::string token;

			while(std::getline(ss, token, '-')) 
			{
				std::cout << token << '\n';
			}
		}
};


As noted in the code above, my problem is that I am not sure how to fill the values in the instance of type Src class. Should I create new instance for it? Or there is some way how to add it directly to the vector?

All I want is to add 1 new object to sources and 1 to destination having the file name saved in member file .

Last edited on
Topic archived. No new replies allowed.