25 using std::stringstream;
33 for (
auto&& kv : *
this)
34 cout <<
"(" << keyFormatter(kv.first) <<
", " << kv.second <<
")";
40 if (this->
size() != x.size())
return false;
42 auto it2 = this->begin();
43 for (; it1 != x.end(); ++it1, ++it2) {
44 if (it1->first != it2->first || it1->second != it2->second)
return false;
51 for (
const auto& kv : values) {
52 if (count(kv.first)) {
53 throw std::out_of_range(
54 "Requested to insert a DiscreteValues into another DiscreteValues " 55 "that already contains one or more of its keys.");
65 for (
const auto& kv : values) {
66 if (!count(kv.first)) {
67 throw std::out_of_range(
68 "Requested to update a DiscreteValues with another DiscreteValues " 69 "that contains keys not present in the first.");
71 (*this)[kv.first] = kv.second;
84 return names.at(key)[index];
93 ss <<
"|Variable|value|\n|:-:|:-:|\n";
96 for (
const auto& kv : *
this) {
97 ss <<
"|" << keyFormatter(kv.first) <<
"|" 98 <<
Translate(names, kv.first, kv.second) <<
"|\n";
110 ss <<
"<div>\n<table class='DiscreteValues'>\n <thead>\n";
113 ss <<
" <tr><th>Variable</th><th>value</th></tr>\n";
116 ss <<
" </thead>\n <tbody>\n";
119 for (
const auto& kv : *
this) {
121 ss <<
"<th>" << keyFormatter(kv.first) <<
"</th><td>" 122 <<
Translate(names, kv.first, kv.second) <<
"</td>";
125 ss <<
" </tbody>\n</table>\n</div>";
132 return values.
markdown(keyFormatter, names);
137 return values.
html(keyFormatter, names);
const gtsam::Symbol key('X', 0)
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a markdown table.
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a html table.
DiscreteValues & update(const DiscreteValues &values)
bool equals(const DiscreteValues &x, double tol=1e-9) const
equals required by Testable for unit testing.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
static std::stringstream ss
static std::string Translate(const Names &names, Key key, size_t index)
Translate an integer index value for given key to a string.
std::pair< iterator, bool > insert(const value_type &value)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
std::uint64_t Key
Integer nonlinear key type.
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.