Skip to content

Commit

Permalink
Regards issue #10:
Browse files Browse the repository at this point in the history
Workaround for exposed `::util::` symbols in the installed library - hoping for a better solution!
  • Loading branch information
Eyal Rozenberg committed Feb 3, 2020
1 parent 2a3165a commit 2e46789
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 57 deletions.
53 changes: 27 additions & 26 deletions examples/src/monetdb-bp-reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <numeric>
#include <stdexcept>

using util::optional;
using monetdb::util::optional;
using std::string;
using std::flush;
using std::endl;
Expand All @@ -41,35 +41,35 @@ using monetdb::sql_column_name;
optional<std::string> translate_type_name(const char* monetdb_type_name)
{
static const std::unordered_map<typename std::string, std::string> type_translation_for_printing = {
{ "void", util::type_name<void>() },
{ "void", ::util::type_name<void>() },
// { "bit", "bit" },
{ "bte", util::type_name<signed char>(), }, // should this really be signed?
{ "sht", util::type_name<int16_t>() },
{ "bte", ::util::type_name<signed char>(), }, // should this really be signed?
{ "sht", ::util::type_name<int16_t>() },
// { "BAT", "bat" },
{ "int", util::type_name<int>() },
{ "int", ::util::type_name<int>() },
#ifdef MONET_OID32
{ "oid", util::type_name<unsigned int>() },
{ "oid", ::util::type_name<unsigned int>() },
typedef unsigned int oid;
#else
{ "oid", util::type_name<size_t>() },
{ "oid", ::util::type_name<size_t>() },
#endif
#if GDK_VERSION == 061033
#if SIZEOF_WRD == SIZEOF_INT
{ "wrd", util::type_name<int32_t>() },
{ "wrd", ::util::type_name<int32_t>() },
#else
{ "wrd", util::type_name<int32_t>() },
{ "wrd", ::util::type_name<int32_t>() },
#endif
#endif /* GDK_VERSION == 061033 */
// we always have long long in C++11
{ "ptr", "pointer" },
{ "flt", util::type_name<float>() },
{ "dbl", util::type_name<double>() },
{ "lng", util::type_name<long long int>() },
{ "flt", ::util::type_name<float>() },
{ "dbl", ::util::type_name<double>() },
{ "lng", ::util::type_name<long long int>() },
#ifdef HAVE_HGE
#ifdef HAVE___INT128
{ "hge", util::type_name<hge>() },
{ "hge", ::util::type_name<hge>() },
#else
{ "hge", util::type_name<__int128_t>() },
{ "hge", ::util::type_name<__int128_t>() },
#endif
#endif
// { "str", "string" },
Expand Down Expand Up @@ -144,7 +144,7 @@ void list_all_columns(
std::pair<filesystem::path, optional<sql_column_name>> parse_cmdline(int argc, char** argv)
{
std::string column_physical_name;
auto binary_name = util::leaf_of(filesystem::path(argv[0]));
auto binary_name = monetdb::util::leaf_of(filesystem::path(argv[0]));
if (not (argc == 2 or argc == 4)) {
die(std::string("Usage:\n") +
binary_name.string() + " DATABASE_ROOT_FOLDER [TABLE_NAME COLUMN_NAME]");
Expand Down Expand Up @@ -269,11 +269,12 @@ void list_column_fully(const column_proxy& column)
list_column_record("Tail", column.record());
}


namespace monetdb {
namespace util {
// This comes from dump.h ... ugly secret dependence, fix it
void sanitize_to(std::ostream& os, char c, unsigned int field_width = 0);
}
} // namespace monetdb

// TODO: Super-ugly code here, sorry
namespace detail {
Expand All @@ -282,13 +283,13 @@ template <typename Iterator>
inline void sanitize_to(std::ostream& os, Iterator begin, Iterator end, unsigned int field_width = 0)
{
std::for_each(begin,end, [&os, field_width](typename std::add_const<decltype(*begin)>::type & e) {
util::sanitize_to(os, e, field_width);
monetdb::util::sanitize_to(os, e, field_width);
});
}

template <typename Iterator>
inline std::string sanitize(Iterator begin, Iterator end, unsigned int field_width = 0) {
auto& oss = util::detail::get_ostringstream();
auto& oss = monetdb::util::detail::get_ostringstream();

sanitize_to(oss, begin, end, field_width);
return oss.str();
Expand All @@ -300,7 +301,7 @@ inline std::string sanitize(Iterator begin, Iterator end, unsigned int field_wid
void dump_string_column(
const column_proxy column,
const size_t max_num_element_to_print,
util::dump_parameters_t dump_params)
monetdb::util::dump_parameters_t dump_params)
{
enum { default_num_elements_to_print = 1024 };

Expand All @@ -310,10 +311,10 @@ void dump_string_column(

std::string tail_type_name;
switch(width) {
case 1: tail_type_name = util::type_name<uint8_t>(); break;
case 2: tail_type_name = util::type_name<uint16_t>(); break;
case 4: tail_type_name = util::type_name<uint32_t>(); break;
case 8: tail_type_name = util::type_name<uint64_t>(); break;
case 1: tail_type_name = ::util::type_name<uint8_t>(); break;
case 2: tail_type_name = ::util::type_name<uint16_t>(); break;
case 4: tail_type_name = ::util::type_name<uint32_t>(); break;
case 8: tail_type_name = ::util::type_name<uint64_t>(); break;
default:
throw invalid_argument("Dump requested for a string column "
"with unsupported tail width: " + std::to_string(width));
Expand Down Expand Up @@ -357,7 +358,7 @@ void dump_string_column(

void dump_string_column(
const column_proxy column,
util::dump_parameters_t dump_params = {})
monetdb::util::dump_parameters_t dump_params = {})
{
dump_string_column(column, column.length(), dump_params);
}
Expand All @@ -377,7 +378,7 @@ void dump_column(

auto tail_type = column.type();

util::dump_parameters_t dump_params;
monetdb::util::dump_parameters_t dump_params;
dump_params.subrange_to_print.set_length(
max_num_elements_to_print.value_or(default_num_elements_to_print)
);
Expand All @@ -397,7 +398,7 @@ void dump_column(
<< "which we can't translate into a type we know how to dump.\n";
return;
}
util::dump(cout, column.at(0), translated_tail_type_name.value(), count, "Tail data", dump_params);
monetdb::util::dump(cout, column.at(0), translated_tail_type_name.value(), count, "Tail data", dump_params);
}

void list_and_dump_all_columns_fully(buffer_pool& pool)
Expand Down
28 changes: 15 additions & 13 deletions examples/src/util/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using std::logic_error;
using std::invalid_argument;
#endif

namespace monetdb {
namespace util {

enum { bits_per_byte = CHAR_BIT, bits_per_char = CHAR_BIT, log_bits_per_char = 3 };
Expand Down Expand Up @@ -245,7 +246,7 @@ struct augmented_params_t : dump_parameters_t {
(extra_info.row_indices ? widths.index + widths.index_to_first_column : 0);
auto data_columns_width = num_elements_per_line * widths.column;
auto num_column_group_beginnings = has_value(num_columns_per_group) ?
util::div_rounding_up(num_elements_per_line, num_columns_per_group.value()) : 0;
::util::div_rounding_up(num_elements_per_line, num_columns_per_group.value()) : 0;
auto num_inter_column_group_stretches =
has_value(num_columns_per_group) ?
num_column_group_beginnings - 1 : 0;
Expand Down Expand Up @@ -320,11 +321,11 @@ struct augmented_params_t : dump_parameters_t {
}

if (has_value(bounds.max)) {
width_t candidate = util::round_down(
width_t candidate = ::util::round_down(
bounds.max.value(), parent::num_elements_per_line.modulus.value());
return (candidate >= bounds.min ? candidate : bounds.max.value());
}
return util::round_up(bounds.min, parent::num_elements_per_line.modulus.value());
return ::util::round_up(bounds.min, parent::num_elements_per_line.modulus.value());
}

width_t width_of(const Datum& x) const
Expand Down Expand Up @@ -386,15 +387,15 @@ struct augmented_params_t : dump_parameters_t {
(width_t) dump_parameters_t::num_elements_per_line_t::defaults::modulus;

data_length = (data_end - data_start) * (dump_bits ? size_t{size_in_bits<Datum>::value} : size_t{1});
subrange_to_print.start = util::clip<size_t>(
subrange_to_print.start = ::util::clip<size_t>(
parent::subrange_to_print.start.value_or(0), 0, parent::subrange_to_print.end.value_or(data_length));
if (subrange_to_print.start == data_length) {
throw logic_error("Invalid subrange of elements to print");
}
if (subrange_to_print.start == std::numeric_limits<size_t>::max()) {
throw logic_error("Invalid subrange of elements to print");
}
subrange_to_print.end = util::clip<size_t>(
subrange_to_print.end = ::util::clip<size_t>(
parent::subrange_to_print.end.value_or(data_length), subrange_to_print.start + 1, data_length);

if (dump_bits) {
Expand Down Expand Up @@ -516,7 +517,7 @@ static void print_header(
stream << dec;
stream << "Consists of " << params.data_length;
if (params.dump_bits) { stream << " bits in container"; }
stream << " elements of type \"" << type_name<E>() << "\" (sized " << sizeof(E) << " bytes).";
stream << " elements of type \"" << ::util::type_name<E>() << "\" (sized " << sizeof(E) << " bytes).";
}
if (params.extra_info.total_size_in_bytes) {
if (printed_anything) { stream << ' '; }
Expand Down Expand Up @@ -604,7 +605,7 @@ static void print_column_headings(
if (at_end_of_line) { break; }
auto between_column_groups =
has_value(params.num_columns_per_group) and
util::divides(params.num_columns_per_group.value(), column_index + 1);
::util::divides(params.num_columns_per_group.value(), column_index + 1);
dump_parameters_t::width_t post_column_space = between_column_groups ?
adjusted.between_column_groups : adjusted.between_columns;
stream << make_spaces(post_column_space);
Expand Down Expand Up @@ -642,8 +643,8 @@ void print_data_rows(
struct {
size_t start, end;
} indexed_positions = {
util::round_down(params.subrange_to_print.start, params.num_elements_per_line),
util::round_up(params.subrange_to_print.end, params.num_elements_per_line)
::util::round_down(params.subrange_to_print.start, params.num_elements_per_line),
::util::round_up(params.subrange_to_print.end, params.num_elements_per_line)
};
data += params.dump_bits ?
params.bit_container_element_access_range.value().start :
Expand All @@ -654,7 +655,7 @@ void print_data_rows(
uint64_t promoted_bit_container_element = *data;
for(size_t pos = indexed_positions.start; pos < indexed_positions.end; pos++)
{
auto at_start_of_new_line = util::divides(params.num_elements_per_line, pos);
auto at_start_of_new_line = ::util::divides(params.num_elements_per_line, pos);
if (at_start_of_new_line) {
stream << make_spaces(params.widths.row_margins.start);
if (std::is_arithmetic<element_type>::value and
Expand Down Expand Up @@ -702,14 +703,14 @@ void print_data_rows(
else { stream << make_spaces(params.widths.column); }
auto next_pos = pos + 1;
auto at_end_of_line = (not params.print_data_on_single_line) and
(util::divides(params.num_elements_per_line, next_pos) or
(::util::divides(params.num_elements_per_line, next_pos) or
(next_pos == params.subrange_to_print.end));
if (at_end_of_line) {
stream << make_spaces(params.widths.row_margins.end) << '\n';
}
else {
auto at_end_of_column_group = params.num_columns_per_group and
util::divides(params.num_columns_per_group.value(), next_pos);
::util::divides(params.num_columns_per_group.value(), next_pos);
stream << make_spaces(at_end_of_column_group ?
params.widths.between_column_groups : params.widths.between_columns);
}
Expand Down Expand Up @@ -752,7 +753,7 @@ void type_unerasure_dump(
if (alignof(decltype(array)) < alignof(E)) {
auto& ss = detail::get_ostringstream();
ss << "Cannot dump the array named \"" << title << "\", at address " << array << " as an array of "
<< util::type_name<E>() << "'s, as it's not aligned on a " << alignof(E) << "-byte boundary "
<< ::util::type_name<E>() << "'s, as it's not aligned on a " << alignof(E) << "-byte boundary "
<< "(its alignment is " << alignof(decltype(array)) << ").";
throw logic_error(ss.str());
}
Expand Down Expand Up @@ -790,3 +791,4 @@ MAP(INSTANTIATE_DUMP_BOTH, int, unsigned int, long, char, unsigned char)
}

} // namespace util
} // namespace monetdb
2 changes: 2 additions & 0 deletions examples/src/util/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <functional>
#include <string>

namespace monetdb {
namespace util {

struct dump_parameters_t {
Expand Down Expand Up @@ -208,5 +209,6 @@ inline streamable_gadget_t dump(
// what about "promotion for printing"?

} // namespace util
} // namespace monetdb

#endif /* UTIL_DUMP_H_ */
4 changes: 4 additions & 0 deletions src/util/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <iostream>
#endif

namespace monetdb {

namespace util {

namespace detail {
Expand Down Expand Up @@ -149,4 +151,6 @@ bool is_readable(const filesystem::path& path)
// return (access(path.string.c_str(), R_OK) == 0);
}

} // namespace monetdb

} /* namespace util */
5 changes: 5 additions & 0 deletions src/util/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace filesystem = boost::filesystem;
#include <string>
#include <vector>

namespace monetdb {

namespace util {

optional<unsigned> get_terminal_width(std::ostream& os);
Expand Down Expand Up @@ -67,4 +69,7 @@ inline auto leaf_of(const filesystem::path& path) {

} /* namespace util */

} // namespace monetdb


#endif /* SRC_UTIL_FILES_H_ */
Loading

0 comments on commit 2e46789

Please sign in to comment.