-
Notifications
You must be signed in to change notification settings - Fork 83
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
1 parent
56c6fe1
commit d84af5e
Showing
38 changed files
with
3,933 additions
and
396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "odb_output_settings.hpp" | ||
#include "common/lut.hpp" | ||
#include "nlohmann/json.hpp" | ||
|
||
namespace horizon { | ||
|
||
const LutEnumStr<ODBOutputSettings::Format> format_lut = { | ||
{"directory", ODBOutputSettings::Format::DIRECTORY}, | ||
{"zip", ODBOutputSettings::Format::ZIP}, | ||
{"tgz", ODBOutputSettings::Format::TGZ}, | ||
}; | ||
|
||
ODBOutputSettings::ODBOutputSettings(const json &j) | ||
: format(format_lut.lookup(j.at("format"))), job_name(j.at("job_name").get<std::string>()), | ||
output_filename(j.at("output_filename").get<std::string>()), | ||
output_directory(j.at("output_directory").get<std::string>()) | ||
{ | ||
} | ||
|
||
void ODBOutputSettings::update_for_board(const Board &brd) | ||
{ | ||
} | ||
|
||
json ODBOutputSettings::serialize() const | ||
{ | ||
json j; | ||
j["format"] = format_lut.lookup_reverse(format); | ||
j["job_name"] = job_name; | ||
j["output_filename"] = output_filename; | ||
j["output_directory"] = output_directory; | ||
return j; | ||
} | ||
} // namespace horizon |
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,28 @@ | ||
#pragma once | ||
#include "common/common.hpp" | ||
#include "common/lut.hpp" | ||
#include "nlohmann/json_fwd.hpp" | ||
#include "util/uuid.hpp" | ||
|
||
namespace horizon { | ||
using json = nlohmann::json; | ||
|
||
class ODBOutputSettings { | ||
public: | ||
ODBOutputSettings(const json &); | ||
ODBOutputSettings() | ||
{ | ||
} | ||
json serialize() const; | ||
void update_for_board(const class Board &brd); | ||
|
||
enum class Format { DIRECTORY, TGZ, ZIP }; | ||
|
||
Format format = Format::TGZ; | ||
|
||
std::string job_name; | ||
|
||
std::string output_filename; | ||
std::string output_directory; | ||
}; | ||
} // namespace horizon |
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,82 @@ | ||
#include "attribute_util.hpp" | ||
#include <sstream> | ||
#include <iomanip> | ||
#include "util/once.hpp" | ||
#include "odb_util.hpp" | ||
|
||
namespace horizon::ODB { | ||
|
||
namespace attribute::detail { | ||
std::string make_legal_string_attribute(const std::string &n) | ||
{ | ||
std::string out; | ||
out.reserve(n.size()); | ||
for (auto c : utf8_to_ascii(n)) { | ||
if (isgraph(c) || c == ' ') | ||
; | ||
else if (isspace(c)) | ||
c = ' '; | ||
else | ||
c = '_'; | ||
out.append(1, c); | ||
} | ||
|
||
return out; | ||
} | ||
} // namespace attribute::detail | ||
|
||
std::string AttributeProvider::double_to_string(double v, unsigned int n) | ||
{ | ||
std::ostringstream oss; | ||
oss << std::fixed << std::setprecision(n) << v; | ||
return oss.str(); | ||
} | ||
|
||
|
||
static unsigned int get_or_create_text(std::map<std::string, unsigned int> &m, const std::string &t) | ||
{ | ||
if (m.count(t)) { | ||
return m.at(t); | ||
} | ||
else { | ||
auto n = m.size(); | ||
m.emplace(t, n); | ||
return n; | ||
} | ||
} | ||
|
||
unsigned int AttributeProvider::get_or_create_attribute_name(const std::string &name) | ||
{ | ||
return get_or_create_text(attribute_names, name); | ||
} | ||
|
||
unsigned int AttributeProvider::get_or_create_attribute_text(const std::string &name) | ||
{ | ||
return get_or_create_text(attribute_texts, name); | ||
} | ||
|
||
void RecordWithAttributes::write_attributes(std::ostream &ost) const | ||
{ | ||
Once once; | ||
for (const auto &attr : attributes) { | ||
if (once()) | ||
ost << " ;"; | ||
else | ||
ost << ","; | ||
ost << attr.first; | ||
if (attr.second.size()) | ||
ost << "=" << attr.second; | ||
} | ||
} | ||
|
||
void AttributeProvider::write_attributes(std::ostream &ost, const std::string &prefix) const | ||
{ | ||
for (const auto &[name, n] : attribute_names) { | ||
ost << prefix << "@" << n << " " << name << endl; | ||
} | ||
for (const auto &[name, n] : attribute_texts) { | ||
ost << prefix << "&" << n << " " << name << endl; | ||
} | ||
} | ||
|
||
} // namespace horizon::ODB |
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,64 @@ | ||
#pragma once | ||
#include "attributes.hpp" | ||
#include <type_traits> | ||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
|
||
namespace horizon::ODB { | ||
|
||
class AttributeProvider { | ||
|
||
public: | ||
template <typename Tr, typename Ta> void add_attribute(Tr &r, Ta v) | ||
{ | ||
using Tc = typename Tr::template check_type<Ta>; | ||
static_assert(Tc::value); | ||
|
||
const auto id = get_or_create_attribute_name(attribute::attribute_name<Ta>::name); | ||
if constexpr (std::is_enum_v<Ta>) | ||
r.attributes.emplace_back(id, std::to_string(static_cast<int>(v))); | ||
else | ||
r.attributes.emplace_back(id, attr_to_string(v)); | ||
} | ||
|
||
protected: | ||
unsigned int get_or_create_attribute_name(const std::string &name); | ||
|
||
void write_attributes(std::ostream &ost, const std::string &prefix = "") const; | ||
|
||
|
||
private: | ||
unsigned int get_or_create_attribute_text(const std::string &name); | ||
|
||
static std::string double_to_string(double v, unsigned int n); | ||
|
||
template <typename T, unsigned int n> std::string attr_to_string(attribute::float_attribute<T, n> a) | ||
{ | ||
return double_to_string(a.value, a.ndigits); | ||
} | ||
|
||
template <typename T> std::string attr_to_string(attribute::boolean_attribute<T> a) | ||
{ | ||
return ""; | ||
} | ||
|
||
template <typename T> std::string attr_to_string(attribute::text_attribute<T> a) | ||
{ | ||
return std::to_string(get_or_create_attribute_text(a.value)); | ||
} | ||
|
||
|
||
std::map<std::string, unsigned int> attribute_names; | ||
std::map<std::string, unsigned int> attribute_texts; | ||
}; | ||
|
||
class RecordWithAttributes { | ||
|
||
protected: | ||
void write_attributes(std::ostream &ost) const; | ||
|
||
public: | ||
std::vector<std::pair<unsigned int, std::string>> attributes; | ||
}; | ||
} // namespace horizon::ODB |
Oops, something went wrong.