I'm using this website as a reference and am modifying some code to (hopefully) have it work the way I'd like it to.
I think I'm close, but since I have no experience with custom paramaterized output manipulators (and have limited experience with custom output manipulators even) I'm kind of caught up.
My functions, with how I believe is the way I'd like to have the parameters issued, is:
First, within the class's header that will be using these manipulators I'd define these:
typedef map<ostream *, string> FlagMap;
static FlagMap Flags;
Then, outside of the class but within the header the following will be there:
struct yearManip {};
extern void year(yearManip x);
typedef void(*yearPtr)(yearManip);
extern ostream &operator << (ostream &out, yearPtr);[/code]
In the cc file, I'd have this:
Calendar::FlagMap Calendar::Flags;
void year(yearManip x) {}
ostream &operator << (ostream &out, yearPtr) {
Calendar::Flags[&out] = "year";
return out;
}
The above compiles happily, even when given an int as a parameter to the manipulator.
My problem is that I don't know how to retrieve the value of the int that's entered as a parameter for the manipulator. In the case above, my program will (as if on a calendar) display the one full calendar year that is entered as a number within the parameter).
Example of intended code usage:
Calendar mine;
cout << year(2010) << mine << endl;
The above would output the full calendar year for the year 2010.
I have all of the functions working correctly, already, but am having trouble understanding how to retrieve the parameter value so I can use the functions in this manipulator.
Can someone please help me understand how to retrieve that value so I can use it? It wouldn't be used by the user in any way...or in the final program. Just within the "Calendar" class's header and source file
Thanks in advance
-Josh
EDIT:
For example, this is the code I specifically need help with:
void year(yearManip x) {}
ostream &operator << (ostream &out, yearPtr) {
Calendar::Flags[&out] = "year";
Calendar::FlagsInt[&out] = yearPtr->x;
return out;
}
(I decided to create a second FlagMap to store the ints relative to the ostream...so the same ostream can reference both the string and int)
I can't getCalendar::FlagsInt[&out] = yearPtr->x;
to reference x, or Calendar::FlagsInt[&out] = yearManip.x;
or any other variation I've tried so far