Skip to content

Commit

Permalink
bdld_DatumUtil::[safe]{T|t}ypedPrint (#4718)
Browse files Browse the repository at this point in the history
  • Loading branch information
cppguru authored and GitHub Enterprise committed May 15, 2024
1 parent aa239a6 commit 337a4ce
Show file tree
Hide file tree
Showing 19 changed files with 2,115 additions and 191 deletions.
22 changes: 11 additions & 11 deletions groups/bdl/bdlb/bdlb_indexspanutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ BSLS_IDENT("$Id: $")
//
///Example1: Taking a IPv6 address out of a URI
/// - - - - - - - - - - - - - - - - - - - - - -
// Suppose we a class that stores a parsed URL using a string to store the full
// URL and 'IndexSpan' objects to describe the individual parts of the URL, and
// we want to add accessors that handle the case when the host part of the URL
// is an IPv6 address, such as "http://[ff:fe:9]/index.html". As observed, an
// IPv6 address is indicated by the '[' and ']' characters (the URL is ill
// formed if the closing ']' is not present). We want to implement two
// methods, one to query if the host part of the URL is IPv6 ('isIPv6Host') and
// another to get the IPv6 address (the part without the square brackets) if
// the host is actually an IPv6 address ('getIPv6Host').
// Suppose we have a class that stores a parsed URL using a string to store the
// full URL and 'IndexSpan' objects to describe the individual parts of the
// URL, and we want to add accessors that handle the case when the host part of
// the URL is an IPv6 address, such as "http://[ff:fe:9]/index.html". As
// observed, an IPv6 address is indicated by the '[' and ']' characters (the
// URL is ill formed if the closing ']' is not present). We want to implement
// two methods, one to query if the host part of the URL is IPv6 ('isIPv6Host')
// and another to get the IPv6 address (the part without the square brackets)
// if the host is actually an IPv6 address ('getIPv6Host').
//
// First let us create a 'ParsedUrl' class. For brevity, the class has only
// First, let us create a 'ParsedUrl' class. For brevity, the class has only
// those parts that are needed to implement 'isIPv6Host' and 'getIPv6Host'.
//..
// class ParsedUrl {
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace bdlb {

struct IndexSpanUtil {
// This struct serves as a namespace for utility functions that operate on
// 'IndexSpan'objects.
// 'IndexSpan' objects.
public:
// CLASS METHODS
static IndexSpan shrink(const IndexSpan& original,
Expand Down
20 changes: 10 additions & 10 deletions groups/bdl/bdlb/bdlb_indexspanutil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ typedef bdlb::IndexSpanUtil Util;
//
///Example1: Taking a IPv6 address out of a URI
/// - - - - - - - - - - - - - - - - - - - - - -
// Suppose we a class that stores a parsed URL using a string to store the full
// URL and 'IndexSpan' objects to describe the individual parts of the URL and.
// we want to add accessors that handle the case when the host part of the URL
// is an IPv6 address, such as "http://[ff:fe:9]/index.html". As observed, an
// IPv6 address is indicated by the '[' and ']' characters (the URL is ill
// formed if the closing ']' is not present). We want to implement two
// methods, one to query if the host part of the URL is IPv6 ('isIPv6Host') and
// another to get the IPv6 address (the part without the square brackets) if
// the host is actually an IPv6 address ('getIPv6Host').
// Suppose we have a class that stores a parsed URL using a string to store the
// full URL and 'IndexSpan' objects to describe the individual parts of the
// URL, and we want to add accessors that handle the case when the host part of
// the URL is an IPv6 address, such as "http://[ff:fe:9]/index.html". As
// observed, an IPv6 address is indicated by the '[' and ']' characters (the
// URL is ill formed if the closing ']' is not present). We want to implement
// two methods, one to query if the host part of the URL is IPv6 ('isIPv6Host')
// and another to get the IPv6 address (the part without the square brackets)
// if the host is actually an IPv6 address ('getIPv6Host').
//
// First let us create a 'ParsedUrl' class. For brevity, the class has only
// First, let us create a 'ParsedUrl' class. For brevity, the class has only
// those parts that are needed to implement 'isIPv6Host' and 'getIPv6Host'.
//..
class ParsedUrl {
Expand Down
16 changes: 12 additions & 4 deletions groups/bdl/bdld/bdld_datum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static const Datum *findElementLinear(const bslstl::StringRef& key,
// ========================
// class Datum_ArrayProctor
// ========================

template <class ELEMENT>
class Datum_ArrayProctor {
// This component-local mechanism class provides a specialized proctor
Expand Down Expand Up @@ -460,7 +461,7 @@ Datum_CopyVisitor::Datum_CopyVisitor(Datum *result,
// MANIPULATORS
void Datum_CopyVisitor::operator()(bslmf::Nil value)
{
(void) value;
(void)value;
*d_result_p = Datum::createNull();
}

Expand Down Expand Up @@ -588,7 +589,6 @@ class Datum_StreamVisitor {
template <class BDLD_TYPE>
void operator()(const BDLD_TYPE& value) const;
// Write the specified 'value' into 'd_stream'.

};

// -------------------------
Expand All @@ -607,7 +607,7 @@ Datum_StreamVisitor::Datum_StreamVisitor(bsl::ostream& stream,
// MANIPULATORS
void Datum_StreamVisitor::operator()(bslmf::Nil value) const
{
(void) value;
(void)value;
if (!d_stream.bad()) {
bdlb::Print::indent(d_stream, d_level, d_spacesPerLevel);
d_stream << "nil";
Expand Down Expand Up @@ -647,6 +647,10 @@ void Datum_StreamVisitor::operator()(const BDLD_TYPE& value) const
}
}

// ============================================================================
// Utility Functions
// ----------------------------------------------------------------------------

bool compareIntLess(const DatumIntMapEntry& lhs, const DatumIntMapEntry& rhs)
{
return lhs.key() < rhs.key();
Expand Down Expand Up @@ -820,6 +824,10 @@ const Datum *findElementLinear(const bslstl::StringRef& key,

} // close unnamed namespace

// ============================================================================
// Implementation
// ----------------------------------------------------------------------------

namespace BloombergLP {
namespace bdld {

Expand Down Expand Up @@ -883,7 +891,7 @@ Datum Datum::createDecimal64(bdldfp::Decimal64 value,
#else // end - 32 bit / begin - 64 bit
// Avoidance of compiler warning. We don't need to allocate memory to
// store Decimal64 values on 64-bit platform.
(void) basicAllocator;
(void)basicAllocator;

result.d_as.d_type = e_INTERNAL_DECIMAL64;
new (result.theInlineStorage()) bdldfp::Decimal64(value);
Expand Down
11 changes: 11 additions & 0 deletions groups/bdl/bdld/bdld_datummaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,10 @@ class DatumMaker {
// Return a 'bdld::Datum' having the specified 'value', or null if
// 'value' is unset.

bdld::Datum bin(const void *pointer, bsl::size_t size) const;
// Return a binary 'bdld::Datum' having a value that is the copy of the
// memory area described by the specified 'pointer' and 'size'.

#if !BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
template <typename... ELEMENTS>
bdld::Datum a(const ELEMENTS&... elements) const;
Expand Down Expand Up @@ -7758,6 +7762,13 @@ bdld::Datum DatumMaker::operator()(
return value.isNull() ? (*this)() : (*this)(value.value());
}


inline
bdld::Datum DatumMaker::bin(const void *pointer, bsl::size_t size) const
{
return bdld::Datum::copyBinary(pointer, size, d_allocator_p);
}

#if !BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
template <typename... ELEMENTS>
inline
Expand Down
Loading

0 comments on commit 337a4ce

Please sign in to comment.