Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/stan/callbacks/json_writer.hpp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with marking the overrides as such, but we need to do it for every function that overrides or none, or we get the -Werror,-Winconsistent-missing-override in CmdStan

Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,15 @@ class json_writer final : public structured_writer {
*/
void write(const std::string& key, int value) { write_int_like(key, value); }

/**
* Write a key-value pair where the value is an `std::size_t`.
* @param key Name of the value pair
* @param value `std::size_t` to write.
*/
void write(const std::string& key, std::size_t value) {
/// Write a key-value pair with an unsigned long value.
void write(const std::string& key,
unsigned long value) override { // NOLINT(runtime/int)
write_int_like(key, value);
}

/// Write a key-value pair with an unsigned long long value.
void write(const std::string& key,
unsigned long long value) override { // NOLINT(runtime/int)
write_int_like(key, value);
}

Expand All @@ -321,7 +324,7 @@ class json_writer final : public structured_writer {
* @param key Name of the value pair
* @param value `unsigned int` to write.
*/
void write(const std::string& key, unsigned int value) {
void write(const std::string& key, unsigned int value) override {
write_int_like(key, value);
}

Expand Down
18 changes: 10 additions & 8 deletions src/stan/callbacks/structured_writer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef STAN_CALLBACKS_STRUCTURED_WRITER_HPP
#define STAN_CALLBACKS_STRUCTURED_WRITER_HPP

#include <cstdint>
#include <stan/math/prim/fun/Eigen.hpp>
#include <vector>
#include <string>
Expand Down Expand Up @@ -65,12 +64,15 @@ class structured_writer {
*/
virtual void write(const std::string& key, int value) {}

/**
* Write a key-value pair where the value is an `uint64_t`.
* @param key Name of the value pair
* @param value `uint64_t` to write.
*/
virtual void write(const std::string& key, uint64_t value) {}
/// Write a key-value pair with an unsigned long value.
virtual void write(const std::string& key,
unsigned long value // NOLINT(runtime/int)
) {}

/// Write a key-value pair with an unsigned long long value.
virtual void write(const std::string& key,
unsigned long long value // NOLINT(runtime/int)
) {}

/**
* Write a key-value pair where the value is an `long long int`.
Expand All @@ -86,7 +88,7 @@ class structured_writer {
* @param key Name of the value pair
* @param value `unsigned int` to write.
*/
virtual void write(const std::string& key, uint32_t value) {}
virtual void write(const std::string& key, unsigned int value) {}

/**
* Write a key-value pair where the value is a double.
Expand Down
18 changes: 18 additions & 0 deletions src/test/unit/callbacks/json_writer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <stan/callbacks/json_writer.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>
#include <cstdint>
#include <limits>
#include <string>

struct deleter_noop {
Expand Down Expand Up @@ -38,6 +40,22 @@ TEST_F(StanInterfaceCallbacksJsonWriter, begin_end_record) {
EXPECT_EQ("{}", out);
}

TEST_F(StanInterfaceCallbacksJsonWriter, write_unsigned_through_base) {
stan::callbacks::structured_writer& base = writer;
base.begin_record();
base.write("uint", 42U);
base.write("ulong", 4294967295UL);
base.write("ullong", 18446744073709551615ULL);
base.write("size", std::size_t{5});
base.write("uint64", std::numeric_limits<std::uint64_t>::max());
base.end_record();
EXPECT_EQ(
"{\"uint\":42,\"ulong\":4294967295,"
"\"ullong\":18446744073709551615,\"size\":5,"
"\"uint64\":18446744073709551615}",
output_sans_whitespace(ss));
}

TEST_F(StanInterfaceCallbacksJsonWriter, begin_end_named_record) {
writer.begin_record();
writer.begin_record("name");
Expand Down
Loading