You can do it by having each of the functions return "this"...but honestly, that looks kind of odd unless you have a very good reason for that type of functionality. |
Zhuge, thanks you so much!!! My class still works properly. Now my code is 2x simpler more.
Are all 100 functions written in a line such a way? :) |
Thanks you for your funny question!!!
My Edit:
In short, all functions are certainly separated into many types. (GET() - SET() - OPERATE() - ADDITIONAL(),...)
GET() - Currently they are not affected by ("return this") but in future they will be replaced by alias or pointer. :)
SET() - Finished replacing (void -> this)
OPERATE() - "void" is redundant, so all OPERATE() are changed immediately now.
ADDITIONAL() - No need to want 'void' to be kept.
-> Stop using 'void'! It's so horrible!!!!!!!!!!!
But, only an exception : a few special functions will never be applied "this" returning value.
I can't list all functions (they are written on a page 1000 lines !!!!!). But I can show the structure of the class (Demonstration mode)
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
//Short version of Math structure
class Math{ //Math Manager
Math([...]){[...]}~Math([...]){[...]}
///////////////////////////////////////////////////////////////////////////////////////////
struct Data{ //Data Manager
public :
~Data([...]){[...]}Data([...]){[...]}
///////////////////////////////////////////////////////////////////////////////////////////
struct subData{ //Child Sata Manager
subData([...]){[...]}~subData([...]){[...]}
subData *Get(double &value){value = data;return this;}
subData *Set(double value){data = value;return this;}
Data *root(int Pos = -1){return (Pos == -1) ? pData : pData->Go(nPos);}
Math *Mroot(){return pData->root();}
subData *Go(int nPos){return &pData->subData[nPos];}
//[...] Many more functions...
private :
Data *pData;double data;
//[...] Many more variables...
}subdata[100]; //Size example
///////////////////////////////////////////////////////////////////////////////////////////
Data *Get(double &value){value = data;return this;}
Data *Set(double value){data = value;return this;}
Math *root(){return pMath;}
Data *Go(int nPos){return &pMath->data[nPos];}
Data *Calculate(){[...] return this;}
//[...] Many more functions...
private :
Math *pMath;double data;
//[...] Many more variables...
}
///////////////////////////////////////////////////////////////////////////////////////////
data[100]; //Actually it's a pointer (no size)
Math *Calculate(int nCount){[...] return this;}
[...] Too many other functions.... ????!?!?!?!??!
private :
//Many variables
};
|
I only list some of the most popular and important functions which are using in my project. With simple calculation, I can write :
Here, very very awful code :
1 2 3 4 5 6 7 8 9 10 11
|
//Math * mObj
mObj = new Math([...]);
mObj->data[0].Set(12.53);
mObj->data[0].subdata[0].Set(6.22);
mObj->data[0].subdata[1].Set(76.35);
mObj->data[1].Set(24.22);
mObj->data[1].subdata[0].Set(11.13);
mObj->data[1].subdata[1].Set(35.25);
mObj->data[1].subdata[2].Set(17.25);
mObj->Calculate(2);
//Many more commands...?!?!??!?!?!!?!?!??!?!?!?!?!??!?!?!?!?!?!?!??!?!?!?!?!
|
No !!!!!!!!
And the solution (It's best !!!!!!!!!!!!!!!!!) :
1 2
|
mObj->data[0].Set(12.53)->subdata[0]->Set(6.22)->Go(1)->Set(76.35)->root(1)->
Set(24.22)->subdata[0].Set(11.13)->Go(1)->Set(35.25)->Go(2)->Set(17.25)->Mroot()->Calculate(2);
|
Oh, I'm very happy!!!!!! what do you think? :)