So this is basically what I want to do:
#define RS03(obj, a1, a2, a3) {if (_str1 == #a1) _file >> _##a1; if (_str1 == #a2) _file >> _##a2;if (_str1 == #a3) _file >> _##a3; obj (_##a1, _##a2, _##a3);}
These are three arguments, but I also need:
#define RS04(obj, a1, a2, a3, a4)
#define RS05(obj, a1, a2, a3, a4, a5)
#define RS06(obj, a1, a2, a3, a4, a5, a6)
...
So, a variable macro.
Stackoverflow has a number of questions on this topic, but they do not apply to my case.
In the above code, the three parameters a1, a2 and a3 are used both as a string (in the "if" condition) and as a variable (in assignments and in the constructor), and obj is a class (therefore, the Last command in the macro is a constructor call).
The fact is that: suppose I have twenty different classes, each requiring a different amount of input to build.
The macro gets the class name and argument names needed to build an object of this class.
, (. " " ). , "". ( # ## ) .
, ( , ), .
, , (, 1 , 2 , 3 bool ..).
"run", .
:
1 -
2 - ,
:
car {
name = model1
speed = 0.05
}
man {
name = model2
speed = 0.03
male = true
ageclass = 3
}
...
, .
, .
, , :
car {
name = pippo
speed = 0.05
speed = 0.06
speed = 0.07
}
( )
, .
(, 4 ).
, :
car {
name = pippo
speed = 0.05
}
car {
name = pluto
}
, .
, , .
:
1 - ( "" ) T ( ) bool ( , )
2 - (, , ), "", (_name, _speed, _male ..)
3 - , , , ( "" ), "=" , , .
( " = 0,03", 0.03 _name ).
( erros, ):
if (car) {
while (str != "}") {
if (str == "speed") { _file >> _speed; _file >> _str; }
if (str == "male") { _file >> _male; _file >> _str; }
if (str == "ageclass") { _file >> _ageclass; _file >> _str; }
ERROR;
}
car (_speed.get (), _male.get (), _ageclass.get ());
}
get() - - "field", , (.. ), ( ).
"" โ , โ true .
, : -)