Skip to content

Commit

Permalink
Modernization vol 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Jun 26, 2018
1 parent 34e3d06 commit 6b390de
Show file tree
Hide file tree
Showing 64 changed files with 263 additions and 333 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ set(SOURCE_FILES
${HELPERS_DIR}/logger.cpp
${HELPERS_DIR}/string_utils.h
${HELPERS_DIR}/string_utils.cpp
${HELPERS_DIR}/format.h

${CONFIG_DIR}/worker_config.cpp
${CONFIG_DIR}/worker_config.h
Expand Down
6 changes: 3 additions & 3 deletions judges/recodex_token_judge/bpplib/algo/lcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace bpp
* \tparam RES The result type (must be an integral type).
* \tparam CONTAINER Class holding the sequence. The class must have size() method
* and the comparator must be able to get values from the container based on their indices.
* \tparma COMPARATOR Comparator class holds a static method compare(seq1, i1, seq2, i2) -> bool.
* \tparam COMPARATOR Comparator class holds a static method compare(seq1, i1, seq2, i2) -> bool.
* I.e., the comparator is also responsible for fetching values from the seq. containers.
*/
template <typename RES = std::size_t, class CONTAINER, typename COMPARATOR>
Expand All @@ -31,7 +31,7 @@ namespace bpp
const CONTAINER &seq2 = sequence1.size() < sequence2.size() ? sequence1 : sequence2;

std::vector<RES> row((std::size_t) seq2.size());
std::size_t rows = (std::size_t) seq1.size();
auto rows = (std::size_t) seq1.size();

// Dynamic programming - matrix traversal that keeps only the last row.
for (std::size_t r = 0; r < rows; ++r) {
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace bpp
* \tparam RES The result type (must be an integral type).
* \tparam CONTAINER Class holding the sequence. The class must have size() method
* and the comparator must be able to get values from the container based on their indices.
* \tparma COMPARATOR Comparator class holds a static method compare(seq1, i1, seq2, i2) -> bool.
* \tparam COMPARATOR Comparator class holds a static method compare(seq1, i1, seq2, i2) -> bool.
* I.e., the comparator is also responsible for fetching values from the seq. containers.
*/
template <typename IDX = std::size_t, class CONTAINER, typename COMPARATOR>
Expand Down
60 changes: 28 additions & 32 deletions judges/recodex_token_judge/bpplib/cli/args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ namespace bpp
ArgumentException(const std::string &msg) : RuntimeError(msg)
{
}
virtual ~ArgumentException() throw()
{
}
~ArgumentException() noexcept override = default;

/*
* Overloading << operator that uses stringstream to append data to mMessage.
Expand Down Expand Up @@ -106,26 +104,26 @@ namespace bpp
// Constraint checks are done only if the argument is present.
if (isPresent()) {
// Check for collisions.
for (auto it = mConflictsWith.begin(); it != mConflictsWith.end(); ++it) {
if (arguments.find(*it) == arguments.end())
for (const auto &it : mConflictsWith) {
if (arguments.find(it) == arguments.end())
throw(ArgumentException()
<< "Internal Error: Argument '" << mName << "' has unspecified argument '" << *it
<< "Internal Error: Argument '" << mName << "' has unspecified argument '" << it
<< "' on its collision list.");

if (arguments.find(*it)->second->isPresent())
if (arguments.find(it)->second->isPresent())
throw(ArgumentException()
<< "The argument '" << mName << "' conflicts with argument '" << *it << "'.");
<< "The argument '" << mName << "' conflicts with argument '" << it << "'.");
}

// Check for requirements.
for (auto it = mRequiresAlso.begin(); it != mRequiresAlso.end(); ++it) {
if (arguments.find(*it) == arguments.end())
for (const auto & it : mRequiresAlso) {
if (arguments.find(it) == arguments.end())
throw(ArgumentException()
<< "Internal Error: Argument '" << mName << "' has unspecified argument '" << *it
<< "Internal Error: Argument '" << mName << "' has unspecified argument '" << it
<< "' on its requirements list.");

if (!arguments.find(*it)->second->isPresent())
throw(ArgumentException() << "The argument '" << *it << "' is also required when '" << mName
if (!arguments.find(it)->second->isPresent())
throw(ArgumentException() << "The argument '" << it << "' is also required when '" << mName
<< "' was specified.");
}
}
Expand Down Expand Up @@ -161,9 +159,7 @@ namespace bpp
}

// Enforce virtual destructor for descendants.
virtual ~ArgBase()
{
}
virtual ~ArgBase() = default;


/**
Expand Down Expand Up @@ -242,10 +238,10 @@ namespace bpp
class ArgBool : public ArgBase
{
public:
typedef bool value_t;
using value_t = bool;

protected:
virtual void process(int &, const char **&)
void process(int &, const char **&) override
{
this->mPresent = true;
}
Expand All @@ -269,7 +265,7 @@ namespace bpp
class ArgIntBase : public ArgBase
{
public:
typedef std::int64_t value_t;
using value_t = std::int64_t;

protected:
value_t mMin; ///< Range constraint for the value.
Expand Down Expand Up @@ -350,7 +346,7 @@ namespace bpp
value_t mValue; ///< Parsed value of the argument.

protected:
virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
mValue = this->processInt(argc, argv);
this->mPresent = true;
Expand Down Expand Up @@ -420,7 +416,7 @@ namespace bpp
std::vector<value_t> mValues; ///< Parsed values of the argument.

protected:
virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
if (!this->mPresent) mValues.clear();

Expand Down Expand Up @@ -479,7 +475,7 @@ namespace bpp
class ArgFloatBase : public ArgBase
{
public:
typedef double value_t;
using value_t = double;

protected:
value_t mMin; ///< Range constraint for the value.
Expand Down Expand Up @@ -548,7 +544,7 @@ namespace bpp
value_t mValue; ///< Parsed value of the argument.

protected:
virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
mValue = this->processFloat(argc, argv);
this->mPresent = true;
Expand Down Expand Up @@ -583,7 +579,7 @@ namespace bpp
std::vector<value_t> mValues; ///< Parsed values of the argument.

protected:
virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
if (!this->mPresent) mValues.clear();

Expand Down Expand Up @@ -643,12 +639,12 @@ namespace bpp
class ArgString : public ArgBase
{
public:
typedef std::string value_t;
using value_t = std::string;

protected:
std::string mValue; ///< The value of the argument stored after parsing.

virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
if (argc == 0)
throw(ArgumentException() << "Value of argument '" << this->getName() << "' is missing!");
Expand Down Expand Up @@ -682,7 +678,7 @@ namespace bpp
class ArgEnum : public ArgString
{
public:
typedef std::string value_t;
using value_t = std::string;

private:
std::string mNormalizedValue;
Expand All @@ -702,7 +698,7 @@ namespace bpp
mOptions.insert(mCaseSensitive ? str : toLower(str));
}

virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
ArgString::process(argc, argv);

Expand Down Expand Up @@ -769,7 +765,7 @@ namespace bpp
std::vector<std::string> mValues; ///< The list of values of the argument stored after parsing.

protected:
virtual void process(int &argc, const char **(&argv))
void process(int &argc, const char **(&argv)) override
{
if (argc == 0)
throw(ArgumentException() << "Value of argument '" << this->getName() << "' is missing!");
Expand Down Expand Up @@ -1110,12 +1106,12 @@ namespace bpp
stream << "Usage: " << Path::getFileName(getProgramName()) << std::endl;

stream << "Named arguments:" << std::endl;
for (auto it = mArguments.begin(); it != mArguments.end(); ++it) {
stream << " " << it->first << " - " << it->second->getComment() << std::endl;
for (const auto &mArgument : mArguments) {
stream << " " << mArgument.first << " - " << mArgument.second->getComment() << std::endl;
}

stream << "Nameless arguments (" << mNamelessMin << ", " << mNamelessMax << "):";
for (std::size_t i = 0; i < mNamelessCaptions.size(); ++i) { stream << " " << mNamelessCaptions[i]; }
for (const auto &mNamelessCaption : mNamelessCaptions) { stream << " " << mNamelessCaption; }
stream << std::endl;
}
};
Expand Down
6 changes: 3 additions & 3 deletions judges/recodex_token_judge/bpplib/cli/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace bpp
std::size_t applySizeLimit(LogSeverity &severity)
{
std::size_t total = 0;
for (std::size_t i = (std::size_t) LogSeverity::UNDEFINED; i < (std::size_t) severity; ++i) {
for (auto i = (std::size_t) LogSeverity::UNDEFINED; i < (std::size_t) severity; ++i) {
total += mLengths[(LogSeverity) i];
if (total >= mMaxLength) { // max log length would be exceeded including current severity into output
severity = (LogSeverity) i;
Expand Down Expand Up @@ -215,8 +215,8 @@ namespace bpp
std::size_t size(LogSeverity severity = LogSeverity::ANY) const
{
std::size_t size = 0;
for (std::size_t i = (std::size_t) LogSeverity::UNDEFINED; i <= (std::size_t) severity; ++i) {
LogSeverity s = (LogSeverity) i;
for (auto i = (std::size_t) LogSeverity::UNDEFINED; i <= (std::size_t) severity; ++i) {
auto s = (LogSeverity) i;
auto it = mLengths.find(s);
if (it != mLengths.end()) { size += it->second; }

Expand Down
20 changes: 5 additions & 15 deletions judges/recodex_token_judge/bpplib/misc/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ namespace bpp
StreamException(const std::string &msg) : std::exception(), mMessage(msg)
{
}
virtual ~StreamException() throw()
{
}
~StreamException() noexcept override = default;

virtual const char *what() const throw()
const char *what() const noexcept override
{
return mMessage.c_str();
}
Expand Down Expand Up @@ -68,9 +66,7 @@ namespace bpp
RuntimeError(const std::string &msg) : StreamException(msg)
{
}
virtual ~RuntimeError() throw()
{
}
~RuntimeError() noexcept override = default;


// Overloading << operator that uses stringstream to append data to mMessage.
Expand Down Expand Up @@ -102,10 +98,7 @@ namespace bpp
LogicError(const std::string &msg) : RuntimeError(msg)
{
}
virtual ~LogicError() throw()
{
}

~LogicError() noexcept override = default;

// Overloading << operator that uses stringstream to append data to mMessage.
template <typename T> LogicError &operator<<(const T &data)
Expand Down Expand Up @@ -133,10 +126,7 @@ namespace bpp
NotImplementedError(const std::string &msg) : RuntimeError(msg)
{
}
virtual ~NotImplementedError() throw()
{
}

~NotImplementedError() noexcept override = default;

// Overloading << operator that uses stringstream to append data to mMessage.
template <typename T> NotImplementedError &operator<<(const T &data)
Expand Down
4 changes: 1 addition & 3 deletions judges/recodex_token_judge/bpplib/system/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ namespace bpp
FileError(const std::string &msg) : RuntimeError(msg)
{
}
virtual ~FileError() throw()
{
}
~FileError() noexcept override = default;


// Overloading << operator that uses stringstream to append data to mMessage.
Expand Down
7 changes: 4 additions & 3 deletions judges/recodex_token_judge/bpplib/system/mmap_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace bpp
#ifdef _WIN32
typedef LONGLONG length_t;
#else
typedef size_t length_t;
using length_t = size_t;
#endif

void *mData; ///< Pointer to memory area where the file is mapped.
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace bpp
throw RuntimeError("Cannot mmap the file.");
}
#endif
};
}


/**
Expand Down Expand Up @@ -189,7 +189,8 @@ namespace bpp
if (!opened()) throw RuntimeError("The file must be opened before prepopulation.");

// Traverse the mapped file accessing first dword on each page.
unsigned x, *data = (unsigned *) getData();
unsigned x = 0;
auto *data = (unsigned *) getData();
for (length_t i = 0; i < mLength / 4096; ++i) {
x ^= *data; // read from page
data += 4096 / sizeof(unsigned); // move to another page
Expand Down
16 changes: 8 additions & 8 deletions judges/recodex_token_judge/comparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ template <typename STRING> bool try_get_double(const STRING &str, double &res)
template <typename CHAR = char, typename OFFSET = std::uint32_t> class TokenComparator
{
public:
typedef CHAR char_t;
typedef OFFSET offset_t;
using char_t = CHAR;
using offset_t = OFFSET;

private:
/**
* Internal structure where tokens are loaded if more commplex comparison is required.
*/
struct TokenPair {
typedef std::basic_string<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>> string_t;
using string_t = std::basic_string<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>>;

public:
string_t token[2];
Expand Down Expand Up @@ -201,11 +201,11 @@ template <typename CHAR = char, typename OFFSET = std::uint32_t> class TokenComp
template <typename CHAR = char, typename OFFSET = std::uint32_t, typename RESULT = std::uint32_t> class LineComparator
{
public:
typedef CHAR char_t;
typedef OFFSET offset_t;
typedef RESULT result_t;
typedef typename Reader<CHAR, OFFSET>::Line line_t;
typedef typename Reader<CHAR, OFFSET>::TokenRef token_t;
using char_t = CHAR;
using offset_t = OFFSET;
using result_t = RESULT;
using line_t = typename Reader<CHAR, OFFSET>::Line;
using token_t = typename Reader<CHAR, OFFSET>::TokenRef;

private:
TokenComparator<CHAR, OFFSET> &mTokenComparator; ///< Token comparator used for comparing tokens on the lines.
Expand Down
11 changes: 6 additions & 5 deletions judges/recodex_token_judge/judge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


#include <misc/exception.hpp>
#include <cli/logger.hpp>

#include <vector>
#include <string>
Expand All @@ -17,10 +18,10 @@
template <class READER, class LINE_COMPARATOR> class Judge
{
public:
typedef READER reader_t;
typedef typename READER::Line line_t;
typedef LINE_COMPARATOR line_comparator_t;
typedef typename LINE_COMPARATOR::result_t score_t;
using reader_t = READER;
using line_t = typename READER::Line;
using line_comparator_t = LINE_COMPARATOR;
using score_t = typename LINE_COMPARATOR::result_t;

private:
/**
Expand Down Expand Up @@ -464,4 +465,4 @@ template <class READER, class LINE_COMPARATOR> class Judge
};


#endif
#endif
Loading

0 comments on commit 6b390de

Please sign in to comment.