提交 7f8890e0 编写于 作者: G Gines Hidalgo

Fixed Ubuntu 14 crash

上级 063c0354
......@@ -43,12 +43,12 @@ namespace op
template <typename T>
inline void plainText(const T& value)
{
mOfstream << value;
*upOfstream << value;
}
inline void comma()
{
mOfstream << ",";
*upOfstream << ",";
}
void enter();
......@@ -57,7 +57,7 @@ namespace op
bool mHumanReadable;
long long mBracesCounter;
long long mBracketsCounter;
std::ofstream mOfstream;
std::unique_ptr<std::ofstream> upOfstream; // std::unique_ptr to solve std::move issue in GCC < 5
DELETE_COPY(JsonOfstream);
};
......
......@@ -24,11 +24,11 @@ namespace op
mHumanReadable{humanReadable},
mBracesCounter{0},
mBracketsCounter{0},
mOfstream{filePath}
upOfstream{new std::ofstream{filePath}}
{
try
{
if (!filePath.empty() && !mOfstream.is_open())
if (!filePath.empty() && !upOfstream->is_open())
error("Json file could not be opened.", __LINE__, __FUNCTION__, __FILE__);
}
catch (const std::exception& e)
......@@ -44,7 +44,8 @@ namespace op
{
try
{
std::swap(mOfstream, jsonOfstream.mOfstream);
upOfstream = std::move(jsonOfstream.upOfstream);
// std::swap(upOfstream, jsonOfstream.upOfstream);
}
catch (const std::exception& e)
{
......@@ -59,7 +60,8 @@ namespace op
mHumanReadable = jsonOfstream.mHumanReadable;
mBracesCounter = jsonOfstream.mBracesCounter;
mBracketsCounter = jsonOfstream.mBracketsCounter;
std::swap(mOfstream, jsonOfstream.mOfstream);
upOfstream = std::move(jsonOfstream.upOfstream);
// std::swap(upOfstream, jsonOfstream.upOfstream);
// Return
return *this;
}
......@@ -74,7 +76,7 @@ namespace op
{
try
{
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
if (mBracesCounter != 0 || mBracketsCounter != 0)
{
......@@ -99,7 +101,7 @@ namespace op
try
{
mBracesCounter++;
mOfstream << "{";
*upOfstream << "{";
}
catch (const std::exception& e)
{
......@@ -112,8 +114,8 @@ namespace op
try
{
mBracesCounter--;
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
mOfstream << "}";
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
*upOfstream << "}";
}
catch (const std::exception& e)
{
......@@ -126,8 +128,8 @@ namespace op
try
{
mBracketsCounter++;
mOfstream << "[";
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
*upOfstream << "[";
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
}
catch (const std::exception& e)
{
......@@ -140,8 +142,8 @@ namespace op
try
{
mBracketsCounter--;
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
mOfstream << "]";
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
*upOfstream << "]";
}
catch (const std::exception& e)
{
......@@ -166,8 +168,8 @@ namespace op
{
try
{
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
mOfstream << "\"" + string + "\":";
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
*upOfstream << "\"" + string + "\":";
}
catch (const std::exception& e)
{
......@@ -179,7 +181,7 @@ namespace op
{
try
{
enterAndTab(mOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
enterAndTab(*upOfstream, mHumanReadable, mBracesCounter, mBracketsCounter);
}
catch (const std::exception& e)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册