Skip to content

Commit

Permalink
0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed Jan 25, 2019
1 parent f7122f0 commit 5cd01d6
Show file tree
Hide file tree
Showing 13 changed files with 1,336 additions and 1,072 deletions.
272 changes: 136 additions & 136 deletions include/cpp14/BoardGame.hpp

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions include/cpp14/DungeonBinarization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,61 @@
namespace dtl {

//2値化処理
template<typename STL_, typename Int_>
constexpr void dungeonBinarization(STL_& stl_, const Int_ value_) noexcept {
for (std::size_t i{}; i < stl_.size(); ++i)
for (std::size_t j{}; j < stl_[i].size(); ++j) {
if (stl_[i][j] >= value_) stl_[i][j] = static_cast<Int_>(1);
else stl_[i][j] = static_cast<Int_>(0);
template<typename Matrix_, typename Matrix_Int_>
constexpr void dungeonBinarization(Matrix_& matrix_, const Matrix_Int_ value_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
if (matrix_[row][col] >= value_) matrix_[row][col] = static_cast<Matrix_Int_>(1);
else matrix_[row][col] = static_cast<Matrix_Int_>(0);
}
}

template<typename STL_, typename Int_>
constexpr void dungeonBinarization_RangeBasedFor(STL_& stl_, const Int_ value_) noexcept {
for (auto&& i : stl_)
for (auto&& j : i) {
if (j >= value_) j = static_cast<Int_>(1);
else j = static_cast<Int_>(0);
template<typename Matrix_, typename Matrix_Int_>
constexpr void dungeonBinarization_RangeBasedFor(Matrix_& matrix_, const Matrix_Int_ value_) noexcept {
for (auto&& row : matrix_)
for (auto&& col : row) {
if (col >= value_) col = static_cast<Matrix_Int_>(1);
else col = static_cast<Matrix_Int_>(0);
}
}

template<typename STL_>
constexpr void dungeonBinarization(STL_& stl_) noexcept {
for (std::size_t i{}; i < stl_.size(); ++i)
for (std::size_t j{}; j < stl_[i].size(); ++j) {
if (stl_[i][j]) stl_[i][j] = 1;
else stl_[i][j] = 0;
template<typename Matrix_>
constexpr void dungeonBinarization(Matrix_& matrix_) noexcept {
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
if (matrix_[row][col]) matrix_[row][col] = 1;
else matrix_[row][col] = 0;
}
}

template<typename STL_>
constexpr void dungeonBinarization_RangeBasedFor(STL_& stl_) noexcept {
for (auto&& i : stl_)
for (auto&& j : i) {
if (j) j = 1;
else j = 0;
template<typename Matrix_>
constexpr void dungeonBinarization_RangeBasedFor(Matrix_& matrix_) noexcept {
for (auto&& row : matrix_)
for (auto&& col : row) {
if (col) col = 1;
else col = 0;
}
}

template<typename STL_, typename STL2_>
constexpr void dungeonBinarizationBool(STL_& stl_, STL2_& stl2_) noexcept {
if (stl_.size() != stl2_.size()) return;
for (std::size_t i{}; i < stl_.size(); ++i)
for (std::size_t j{}; j < stl_[i].size(); ++j) {
if (stl_[i].size() != stl2_[i].size()) continue;
if (stl_[i][j]) stl2_[i][j] = true;
else stl2_[i][j] = false;
template<typename Matrix_, typename STL2_>
constexpr void dungeonBinarizationBool(Matrix_& matrix_, STL2_& stl2_) noexcept {
if (matrix_.size() != stl2_.size()) return;
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
if (matrix_[row].size() != stl2_[row].size()) continue;
if (matrix_[row][col]) stl2_[row][col] = true;
else stl2_[row][col] = false;
}
}

template<typename STL_, typename STL2_, typename Int_>
constexpr void dungeonBinarizationBool(STL_& stl_, STL2_& stl2_, const Int_ value_) noexcept {
if (stl_.size() != stl2_.size()) return;
for (std::size_t i{}; i < stl_.size(); ++i)
for (std::size_t j{}; j < stl_[i].size(); ++j) {
if (stl_[i].size() != stl2_[i].size()) continue;
if (stl_[i][j] >= value_) stl2_[i][j] = true;
else stl2_[i][j] = false;
template<typename Matrix_, typename STL2_, typename Matrix_Int_>
constexpr void dungeonBinarizationBool(Matrix_& matrix_, STL2_& stl2_, const Matrix_Int_ value_) noexcept {
if (matrix_.size() != stl2_.size()) return;
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
if (matrix_[row].size() != stl2_[row].size()) continue;
if (matrix_[row][col] >= value_) stl2_[row][col] = true;
else stl2_[row][col] = false;
}
}

Expand Down
84 changes: 44 additions & 40 deletions include/cpp14/DungeonFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

//Dungeon Template Library Namespace
namespace dtl {
template<typename Int_>
Int_ fileReadSplitReturnValue_CSV(const std::string& field_) noexcept {
return static_cast<Int_>(std::stoi(field_));

//文字として保存された数字を数値に変換する
template<typename Matrix_Int_>
Matrix_Int_ fileReadSplitReturnValue_CSV(const std::string& field_) noexcept {
return static_cast<Matrix_Int_>(std::stoi(field_));
}
template<>
long fileReadSplitReturnValue_CSV<long>(const std::string& field_) noexcept {
Expand Down Expand Up @@ -49,72 +51,74 @@ namespace dtl {
return std::stold(field_);
}

template<typename Int_, typename STL_>
void fileReadSplit_CSV(STL_& stl_, const std::size_t y_id_, std::string& input_line_, const char delimiter_) noexcept {
if (stl_.size() <= y_id_) return;
//csvファイルの読み込み時の分割
template<typename Matrix_Int_, typename Matrix_>
void fileReadSplit_CSV(Matrix_& matrix_, const std::size_t y_id_, std::string& input_line_, const char delimiter_) noexcept {
if (matrix_.size() <= y_id_) return;
std::istringstream stream(input_line_);
std::string field{};
std::size_t x_id{};
while (std::getline(stream, field, delimiter_)) {
if (stl_[y_id_].size() <= x_id) return;
stl_[y_id_][x_id] = fileReadSplitReturnValue_CSV<Int_>(field);
if (matrix_[y_id_].size() <= x_id) return;
matrix_[y_id_][x_id] = fileReadSplitReturnValue_CSV<Matrix_Int_>(field);
++x_id;
}
return;
}

template<typename Int_, typename STL_>
bool fileRead_CSV(STL_& stl_, const std::string& str_, const char delimiter_ = ',') noexcept {
//csvファイルの読み込み
template<typename Matrix_Int_, typename Matrix_>
bool fileRead_CSV(Matrix_& matrix_, const std::string& str_, const char delimiter_ = ',') noexcept {
std::ifstream ifs(str_);
if (ifs.fail()) return false;
std::size_t y_id{};
std::string line{};
while (std::getline(ifs, line)) {
fileReadSplit_CSV<Int_>(stl_, y_id, line, delimiter_);
fileReadSplit_CSV<Matrix_Int_>(matrix_, y_id, line, delimiter_);
++y_id;
}
return true;
}

template<typename Int_, typename STL_>
bool fileWrite_CSV(const STL_& stl_, const std::string& str_) noexcept {
//csvファイルの書き込み
template<typename Matrix_Int_, typename Matrix_>
bool fileWrite_CSV(const Matrix_& matrix_, const std::string& str_) noexcept {
std::ofstream ofs(str_);
if (ofs.fail()) return false;
const bool is_char{ (typeid(Int_) == typeid(unsigned char) || typeid(Int_) == typeid(signed char)) };
for (std::size_t i{}; i < stl_.size(); ++i) {
if (stl_[i].size() == 0) continue;
if(is_char) ofs << static_cast<int>(stl_[i][0]);
else ofs << stl_[i][0];;
for (std::size_t j{ 1 }; j < stl_[i].size(); ++j) {
const bool is_char{ (typeid(Matrix_Int_) == typeid(unsigned char) || typeid(Matrix_Int_) == typeid(signed char)) };
for (std::size_t row{}; row < matrix_.size(); ++row) {
if (matrix_[row].size() == 0) continue;
if(is_char) ofs << static_cast<int>(matrix_[row][0]);
else ofs << matrix_[row][0];
for (std::size_t col{ 1 }; col < matrix_[row].size(); ++col) {
ofs << ',';
if (is_char) ofs << static_cast<int>(stl_[i][j]);
else ofs << stl_[i][j];
if (is_char) ofs << static_cast<int>(matrix_[row][col]);
else ofs << matrix_[row][col];
}
ofs << std::endl;
}
return true;
}

template<typename Int_, typename STL_>
bool fileWrite(const STL_& stl_, const std::string& str_) noexcept {
//バイナリファイルの書き込み
template<typename Matrix_Int_, typename Matrix_>
bool fileWrite(const Matrix_& matrix_, const std::string& str_) noexcept {
std::ofstream ofs(str_, std::ios::binary);
if (ofs.fail()) return false;

std::uint64_t y_max{ static_cast<std::uint64_t>(stl_.size()) };
std::uint64_t x_max{ ((stl_.size() == 0) ? static_cast <std::uint64_t>(0) : static_cast<std::uint64_t>(stl_[0].size())) };
std::uint64_t y_max{ static_cast<std::uint64_t>(matrix_.size()) };
std::uint64_t x_max{ ((matrix_.size() == 0) ? static_cast <std::uint64_t>(0) : static_cast<std::uint64_t>(matrix_[0].size())) };
ofs.write(reinterpret_cast<char *>(&x_max), sizeof(std::uint64_t));
ofs.write(reinterpret_cast<char *>(&y_max), sizeof(std::uint64_t));

Int_ write_value{};
for (std::size_t i{}; i < stl_.size(); ++i)
for (std::size_t j{}; j < stl_[i].size(); ++j) {
write_value = stl_[i][j];
ofs.write(reinterpret_cast<const char *>(&write_value), sizeof(Int_));
Matrix_Int_ write_value{};
for (std::size_t row{}; row < matrix_.size(); ++row)
for (std::size_t col{}; col < matrix_[row].size(); ++col) {
write_value = matrix_[row][col];
ofs.write(reinterpret_cast<const char *>(&write_value), sizeof(Matrix_Int_));
}
return true;
}
template<typename Int_, typename STL_>
bool fileRead(STL_& stl_, const std::string& str_) noexcept {
//バイナリファイルの読み込み
template<typename Matrix_Int_, typename Matrix_>
bool fileRead(Matrix_& matrix_, const std::string& str_) noexcept {
std::ifstream ifs(str_, std::ios::binary);
if (ifs.fail()) return false;
if (ifs.eof()) return false;
Expand All @@ -124,19 +128,19 @@ namespace dtl {
if (ifs.eof()) return false;
ifs.read(reinterpret_cast<char *>(&y_max), sizeof(std::uint64_t));

Int_ read_value{};
Matrix_Int_ read_value{};
std::size_t x_count{};
std::size_t y_count{};
while (!ifs.eof()) {
ifs.read(reinterpret_cast<char *>(&read_value), sizeof(Int_));
ifs.read(reinterpret_cast<char *>(&read_value), sizeof(Matrix_Int_));
if (x_count >= static_cast<std::size_t>(x_max)) {
x_count = static_cast<std::size_t>(0);
++y_count;
}
if (y_count >= stl_.size()) break;
if (x_count >= stl_[y_count].size()) continue;
if (y_count >= matrix_.size()) break;
if (x_count >= matrix_[y_count].size()) continue;

stl_[y_count][x_count] = read_value;
matrix_[y_count][x_count] = read_value;
++x_count;
}
return true;
Expand Down
Loading

0 comments on commit 5cd01d6

Please sign in to comment.