-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
680 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "args.h" | ||
|
||
namespace hydra { | ||
|
||
Args::Args( | ||
std::initializer_list<std::pair<std::string, io::args_t>> const &args) { | ||
for (auto const &[key, val] : args) { | ||
args_[key] = val; | ||
} | ||
} | ||
bool Args::defined(std::string key) const { return args_.count(key); } | ||
io::ArgsHandler Args::operator[](std::string key) { | ||
return io::ArgsHandler(key, args_); | ||
} | ||
|
||
bool Args::operator==(Args const &other) const { return args_ == other.args_; } | ||
bool Args::operator!=(Args const &other) const { return !operator==(other); } | ||
|
||
} // namespace hydra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <map> | ||
#include <initializer_list> | ||
#include <utility> | ||
|
||
#include <hydra/io/args_handler.h> | ||
|
||
namespace hydra { | ||
|
||
class Args { | ||
public: | ||
Args() = default; | ||
Args(std::initializer_list<std::pair<std::string, io::args_t>> const& args); | ||
|
||
bool defined(std::string key) const; | ||
io::ArgsHandler operator[](std::string key); | ||
|
||
bool operator==(Args const &other) const; | ||
bool operator!=(Args const &other) const; | ||
|
||
private: | ||
std::map<std::string, io::args_t> args_; | ||
}; | ||
|
||
} // namespace hydra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "args_handler.h" | ||
|
||
#include <hydra/utils/logger.h> | ||
|
||
namespace hydra::io { | ||
|
||
ArgsHandler::ArgsHandler(std::string key, | ||
std::map<std::string, io::args_t> &args) | ||
: key_(key), args_(args) {} | ||
|
||
template <class data_t> data_t ArgsHandler::as() const { | ||
if (args_.count(key_)) { | ||
return std::get<data_t>(args_.at(key_)); | ||
} else { | ||
Log.err("Error using Args: key \"{}\" not found", key_); | ||
return data_t(); | ||
} | ||
} | ||
template <class data_t> data_t ArgsHandler::as(data_t const &defaultt) const { | ||
if (args_.count(key_)) { | ||
return std::get<data_t>(args_.at(key_)); | ||
} else { | ||
return defaultt; | ||
} | ||
} | ||
|
||
template <class data_t> void ArgsHandler::operator=(data_t const &data) { | ||
args_[key_] = data; | ||
} | ||
|
||
template bool ArgsHandler::as<bool>() const; | ||
template std::string ArgsHandler::as<std::string>() const; | ||
template int8_t ArgsHandler::as<int8_t>() const; | ||
template int16_t ArgsHandler::as<int16_t>() const; | ||
template int32_t ArgsHandler::as<int32_t>() const; | ||
template int64_t ArgsHandler::as<int64_t>() const; | ||
template uint8_t ArgsHandler::as<uint8_t>() const; | ||
template uint16_t ArgsHandler::as<uint16_t>() const; | ||
template uint32_t ArgsHandler::as<uint32_t>() const; | ||
template uint64_t ArgsHandler::as<uint64_t>() const; | ||
template double ArgsHandler::as<double>() const; | ||
template complex ArgsHandler::as<complex>() const; | ||
|
||
template bool ArgsHandler::as(bool const &) const; | ||
template std::string ArgsHandler::as(std::string const &) const; | ||
template int8_t ArgsHandler::as(int8_t const &) const; | ||
template int16_t ArgsHandler::as(int16_t const &) const; | ||
template int32_t ArgsHandler::as(int32_t const &) const; | ||
template int64_t ArgsHandler::as(int64_t const &) const; | ||
template uint8_t ArgsHandler::as(uint8_t const &) const; | ||
template uint16_t ArgsHandler::as(uint16_t const &) const; | ||
template uint32_t ArgsHandler::as(uint32_t const &) const; | ||
template uint64_t ArgsHandler::as(uint64_t const &) const; | ||
template double ArgsHandler::as(double const &) const; | ||
template complex ArgsHandler::as(complex const &) const; | ||
|
||
template void ArgsHandler::operator=(bool const &); | ||
template void ArgsHandler::operator=(std::string const &); | ||
template void ArgsHandler::operator=(int8_t const &); | ||
template void ArgsHandler::operator=(int16_t const &); | ||
template void ArgsHandler::operator=(int32_t const &); | ||
template void ArgsHandler::operator=(int64_t const &); | ||
template void ArgsHandler::operator=(uint8_t const &); | ||
template void ArgsHandler::operator=(uint16_t const &); | ||
template void ArgsHandler::operator=(uint32_t const &); | ||
template void ArgsHandler::operator=(uint64_t const &); | ||
template void ArgsHandler::operator=(double const &); | ||
template void ArgsHandler::operator=(complex const &); | ||
|
||
} // namespace hydra::io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#include <extern/armadillo/armadillo> | ||
#include <hydra/common.h> | ||
|
||
namespace hydra::io { | ||
|
||
using args_t = | ||
std::variant<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, | ||
uint64_t, bool, double, complex, std::string>; | ||
|
||
class ArgsHandler { | ||
public: | ||
ArgsHandler(std::string key, std::map<std::string, io::args_t> &args); | ||
ArgsHandler(ArgsHandler const &) = delete; | ||
ArgsHandler &operator=(ArgsHandler const &) = delete; | ||
|
||
template <class data_t> data_t as() const; | ||
template <class data_t> data_t as(data_t const& defaultt) const; | ||
template <class data_t> void operator=(data_t const &data); | ||
|
||
private: | ||
std::string key_; | ||
std::map<std::string, io::args_t> &args_; | ||
}; | ||
|
||
} // namespace hydra::io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
namespace hydra { | ||
|
||
class U1 { | ||
public: | ||
inline bool operator==(U1 const &rhs) const { | ||
(void)rhs; | ||
return true; | ||
} | ||
inline bool operator!=(U1 const &rhs) const { return !operator==(rhs); } | ||
}; | ||
|
||
} // namespace hydra |
Oops, something went wrong.