Skip to content

Commit

Permalink
Introduce sequence point between input segments
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Mar 29, 2015
1 parent c98c115 commit e61e102
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
13 changes: 5 additions & 8 deletions include/tcframe/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,18 @@ class IOFormatProvider {
}

LineIOSegment& applyLineSegment(string names) {
applyLastSegment();
LineIOSegment* segment = new LineIOSegment(names);
lastSegment = segment;
return *segment;
}

LinesIOSegment& applyLinesSegment(string names) {
applyLastSegment();
LinesIOSegment* segment = new LinesIOSegment(names);
lastSegment = segment;
return *segment;
}

GridIOSegment& applyGridSegment(string name) {
applyLastSegment();
GridIOSegment* segment = new GridIOSegment(name);
lastSegment = segment;
return *segment;
Expand All @@ -421,11 +418,6 @@ class IOFormatProvider {
applyLastSegment();
}

private:
istream* in;
ostream* out;
IOSegment* lastSegment;

void applyLastSegment() {
if (lastSegment == nullptr) {
return;
Expand All @@ -437,6 +429,11 @@ class IOFormatProvider {
lastSegment->printTo(*out);
}
}

private:
istream* in;
ostream* out;
IOSegment* lastSegment;
};

}
Expand Down
8 changes: 4 additions & 4 deletions include/tcframe/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#define SIZE_WITH_COUNT(_1, _2, N, ...) SIZE_IMPL ## N
#define SIZE(...) SIZE_WITH_COUNT(__VA_ARGS__, 2, 1)(__VA_ARGS__)

#define EMPTY_LINE() applyLineSegment("")
#define LINE(...) applyLineSegment(#__VA_ARGS__), __VA_ARGS__
#define LINES(...) (applyLinesSegment(#__VA_ARGS__), __VA_ARGS__)
#define GRID(...) (applyGridSegment(#__VA_ARGS__), __VA_ARGS__)
#define EMPTY_LINE() applyLastSegment(), applyLineSegment("")
#define LINE(...) applyLastSegment(), (applyLineSegment(#__VA_ARGS__), __VA_ARGS__)
#define LINES(...) applyLastSegment(), (applyLinesSegment(#__VA_ARGS__), __VA_ARGS__)
#define GRID(...) applyLastSegment(), (applyGridSegment(#__VA_ARGS__), __VA_ARGS__)

#define CASE(...) addOfficialTestCase([this] {__VA_ARGS__;}, #__VA_ARGS__)
#define SAMPLE_CASE(...) addSampleTestCase(__VA_ARGS__)
Expand Down
8 changes: 4 additions & 4 deletions test/generator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class ProblemWithSubtasks : public BaseProblem {
}

void InputFormat() {
applyLineSegment("A, B"), A, B;
applyLineSegment("K"), K;
applyLastSegment(), (applyLineSegment("A, B"), A, B);
applyLastSegment(), (applyLineSegment("K"), K);
}

void Subtask1() {
Expand Down Expand Up @@ -167,8 +167,8 @@ class ProblemWithoutSubtasks : public BaseProblem {
}

void InputFormat() {
applyLineSegment("A, B"), A, B;
applyLineSegment("K"), K;
applyLastSegment(), (applyLineSegment("A, B"), A, B);
applyLastSegment(), (applyLineSegment("K"), K);
}

void Constraints() {
Expand Down
8 changes: 4 additions & 4 deletions test/io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ TEST(IOFormatProviderTest, Printing) {
ostringstream sout;

provider.beginPrintingFormat(&sout);
provider.applyLineSegment("A, B"), A, B;
provider.applyLineSegment("K"), K;
provider.applyLastSegment(); provider.applyLineSegment("A, B"), A, B;
provider.applyLastSegment(); provider.applyLineSegment("K"), K;
provider.endPrintingFormat();

EXPECT_EQ("1 2\n77\n", sout.str());
Expand All @@ -586,8 +586,8 @@ TEST(IOFormatProviderTest, Parsing) {
istringstream sin("1 2\n77\n");

provider.beginParsingFormat(&sin);
provider.applyLineSegment("A, B"), A, B;
provider.applyLineSegment("K"), K;
provider.applyLastSegment(); provider.applyLineSegment("A, B"), A, B;
provider.applyLastSegment(); provider.applyLineSegment("K"), K;
provider.endPrintingFormat();

EXPECT_EQ(1, A);
Expand Down

0 comments on commit e61e102

Please sign in to comment.