So I want to write an indent output class that can be used like this:
Debug f;
f.open("test.txt");
f << Debug::IndS << "Start" << std::endl;
f << Debug::Ind << "test" << std::endl;
f << Debug::IndE << "End" << std::endl;
which would output:
Start
test
End
So IndS would print out current indent and increment indent, Ind would print out the current indent and IndE would decrement indent and print out the current indent. I have tried to create it like so:
class Debug : public std::ofstream {
public:
Debug();
~Debug();
private:
std::string IndentText;
int _Indent;
public:
void SetIndentText(const char* Text);
inline void Indent(int Amount);
inline void SetIndent(int Amount);
inline std::ofstream& Ind (std::ofstream& ofs);
inline std::ofstream& IndS(std::ofstream& ofs);
inline std::ofstream& IndE(std::ofstream& ofs);
};
Debug::Debug () : std::ofstream() {
IndentText = " ";
}
Debug::~Debug () {
}
void Debug::SetIndentText (const char* Text) {
IndentText = Text;
}
void Debug::Indent (int Amount) {
_Indent += Amount;
}
void Debug::SetIndent(int Amount) {
_Indent = Amount;
}
std::ofstream& Debug::Ind (std::ofstream& ofs) {
for (int i = 0;i < _Indent;i++) {
ofs << IndentText;
}
return ofs;
}
std::ofstream& Debug::IndS (std::ofstream& ofs) {
ofs << Ind;
_Indent++;
return ofs;
}
std::ofstream& Debug::IndE (std::ofstream& ofs) {
_Indent--;
ofs << Ind;
return ofs;
}
So I think there are a few problems with this:
It does not compile. Errors with
no match for 'operator<<' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and '<unresolved overloaded function type>') ofs << Ind; candidates are:
blah blahI don't override all constructors. Is there a way to do this? I think I just have to rewrite all the constructors to do
IndentText = " ";
and delegate the overloaded constructor
Could someone help me with this? Thanks!