Skip to content

Commit

Permalink
Output separator
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Dec 18, 2016
1 parent f8170c1 commit be0e1ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion jngen.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ struct OutputModifier {

bool printParents = false;
bool printEdges = true;

char sep = ' ';
};

OutputModifier defaultMod;
Expand Down Expand Up @@ -338,6 +340,11 @@ class Repr {
return *this;
}

Repr<T>& endl(bool value = true) {
mod_.sep = value ? '\n' : ' ';
return *this;
}

private:
void print(std::ostream& out) const {
printValue(out, object_, mod_, PTagMax{});
Expand Down Expand Up @@ -387,6 +394,12 @@ class ReprProxy {
return repr;
}

Repr<T> endl(bool value = true) {
Repr<T> repr(static_cast<const T&>(*this));
repr.endl(value);
return repr;
}

protected:
ReprProxy() {
static_assert(
Expand Down Expand Up @@ -530,7 +543,7 @@ JNGEN_DECLARE_PRINTER(detail::VectorDepth<T>::value == 1, 3)
if (first) {
first = false;
} else {
out << " ";
out << mod.sep;
}
JNGEN_PRINT(x);
}
Expand Down
2 changes: 1 addition & 1 deletion printers.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ JNGEN_DECLARE_PRINTER(detail::VectorDepth<T>::value == 1, 3)
if (first) {
first = false;
} else {
out << " ";
out << mod.sep;
}
JNGEN_PRINT(x);
}
Expand Down
13 changes: 13 additions & 0 deletions repr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct OutputModifier {

bool printParents = false;
bool printEdges = true;

char sep = ' ';
};

OutputModifier defaultMod;
Expand Down Expand Up @@ -72,6 +74,11 @@ class Repr {
return *this;
}

Repr<T>& endl(bool value = true) {
mod_.sep = value ? '\n' : ' ';
return *this;
}

private:
void print(std::ostream& out) const {
printValue(out, object_, mod_, PTagMax{});
Expand Down Expand Up @@ -121,6 +128,12 @@ class ReprProxy {
return repr;
}

Repr<T> endl(bool value = true) {
Repr<T> repr(static_cast<const T&>(*this));
repr.endl(value);
return repr;
}

protected:
ReprProxy() {
static_assert(
Expand Down

0 comments on commit be0e1ca

Please sign in to comment.