Skip to content

Commit

Permalink
Fix regression when string cannot be used as variable type (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Nov 28, 2016
1 parent 9ba991a commit b8f0319
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/1_0_1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Bugfixes
--------

- Fixed a regression when I/O format segments do not pick up correct sizes taken from I/O variables.
- Fixed a regression when ``std::string`` cannot be used as variable type.
2 changes: 1 addition & 1 deletion ete-test/resources/normal-complex-formats/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
int A, B;

int main() {
printf("1\n");
printf("yes\n");
}
4 changes: 2 additions & 2 deletions ete-test/resources/normal-complex-formats/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ProblemSpec : public BaseProblemSpec {
vector<int> X, Y;
vector<vector<int>> M;

int res;
string res;

void InputFormat() {
LINE(N);
Expand Down Expand Up @@ -46,7 +46,7 @@ class TestSpec : public BaseTestSpec<ProblemSpec> {
"8 8 8"
});
Output({
"1"
"yes"
});
}

Expand Down
22 changes: 10 additions & 12 deletions include/tcframe/spec/variable/Matrix.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <exception>
#include <functional>
#include <iostream>
#include <type_traits>
#include <vector>
Expand All @@ -14,7 +13,6 @@ using std::endl;
using std::iostream;
using std::is_same;
using std::ostream;
using std::reference_wrapper;
using std::ref;
using std::vector;

Expand Down Expand Up @@ -42,40 +40,40 @@ class Matrix : public Variable {
template<typename T, typename = ScalarCompatible<T>>
class MatrixImpl : public Matrix {
private:
reference_wrapper<vector<vector<T>>> var_;
vector<vector<T>>* var_;
bool hasSpaces_;

public:
MatrixImpl(vector<vector<T>>& var, const string& name)
: Matrix(name)
, var_(var)
, var_(&var)
, hasSpaces_(!is_same<T, char>::value) {}

int rows() const {
return (int) var_.get().size();
return (int) var_->size();
}

int columns(int rowIndex) const {
return (int) var_.get()[rowIndex].size();
return (int) (*var_)[rowIndex].size();
}

void clear() {
var_.get().clear();
var_->clear();
}

void printTo(ostream* out) {
for (int row = 0; row < var_.get().size(); row++) {
for (int row = 0; row < var_->size(); row++) {
printRowTo(row, out);
*out << endl;
}
}

void printRowTo(int rowIndex, ostream* out) {
for (int c = 0; c < var_.get()[rowIndex].size(); c++) {
for (int c = 0; c < (*var_)[rowIndex].size(); c++) {
if (c > 0 && hasSpaces_) {
*out << ' ';
}
*out << var_.get()[rowIndex][c];
*out << (*var_)[rowIndex][c];
}
}

Expand All @@ -90,7 +88,7 @@ class MatrixImpl : public Matrix {
Variable::parseValue(in, element, TokenFormatter::formatMatrixElement(name(), r, c));
row.push_back(element);
}
var_.get().push_back(row);
var_->push_back(row);
WhitespaceManipulator::parseNewline(in, TokenFormatter::formatMatrixElement(name(), r, columns - 1));
}
}
Expand All @@ -111,7 +109,7 @@ class MatrixImpl : public Matrix {
Variable::parseValue(in, element, TokenFormatter::formatMatrixElement(name(), rowIndex, c));
row.push_back(element);
}
var_.get().push_back(row);
var_->push_back(row);
}
};

Expand Down
10 changes: 4 additions & 6 deletions include/tcframe/spec/variable/Scalar.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <exception>
#include <functional>
#include <iostream>
#include <string>

Expand All @@ -12,7 +11,6 @@
using std::istream;
using std::ostream;
using std::ref;
using std::reference_wrapper;
using std::string;

namespace tcframe {
Expand All @@ -34,19 +32,19 @@ class Scalar : public Variable {
template<typename T, typename = ScalarCompatible<T>>
class ScalarImpl : public Scalar {
private:
reference_wrapper<T> var_;
T* var_;

public:
ScalarImpl(T& var, const string& name)
: Scalar(name)
, var_(ref(var)) {}
, var_(&var) {}

void printTo(ostream* out) {
*out << var_;
*out << *var_;
}

void parseFrom(istream* in) {
Variable::parseValue(in, var_, TokenFormatter::formatVariable(name()));
Variable::parseValue(in, *var_, TokenFormatter::formatVariable(name()));
}
};

Expand Down
16 changes: 7 additions & 9 deletions include/tcframe/spec/variable/Vector.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <exception>
#include <functional>
#include <iostream>
#include <vector>

Expand All @@ -11,7 +10,6 @@

using std::iostream;
using std::ostream;
using std::reference_wrapper;
using std::ref;
using std::vector;

Expand Down Expand Up @@ -39,24 +37,24 @@ class Vector : public Variable {
template<typename T, typename = ScalarCompatible<T>>
class VectorImpl : public Vector {
private:
reference_wrapper<vector<T>> var_;
vector<T>* var_;

public:
VectorImpl(vector<T>& var, const string& name)
: Vector(name)
, var_(ref(var)) {}
, var_(&var) {}

int size() const {
return (int) var_.get().size();
return (int) var_->size();
}

void clear() {
var_.get().clear();
var_->clear();
}

void printTo(ostream* out) {
bool first = true;
for (T& element : var_.get()) {
for (T& element : *var_) {
if (!first) {
*out << ' ';
}
Expand All @@ -66,7 +64,7 @@ class VectorImpl : public Vector {
}

void printElementTo(int index, ostream* out) {
*out << var_.get()[index];
*out << (*var_)[index];
}

void parseFrom(istream* in) {
Expand Down Expand Up @@ -96,7 +94,7 @@ class VectorImpl : public Vector {
int index = size();
T element;
Variable::parseValue(in, element, TokenFormatter::formatVectorElement(name(), index));
var_.get().push_back(element);
var_->push_back(element);
}
};

Expand Down

0 comments on commit b8f0319

Please sign in to comment.