Class NamedValue¶
Defined in File NamedValue.hpp
Class Documentation¶
-
class NamedValue¶
[source] A named, typed value used throughout the mock framework.
Encapsulates all primitive types and opaque object pointers in a single union so that a heterogeneous collection of parameters can be stored and compared uniformly. Custom types register a NamedValueComparator (for comparison) and a NamedValueCopier (for output parameters) via Support::install_comparator() and Support::install_copier().
Public Types
-
using FunctionPointerValue = void (*)()¶
Type alias for a pointer to a function with signature
void().
Public Functions
-
NamedValue(StringView name)¶
Construct a named value with no data set.
- Parameters:
name – The parameter or data key.
-
NamedValue(const NamedValue&) = default¶
-
NamedValue(NamedValue&&) noexcept¶
-
NamedValue &operator=(NamedValue&&) noexcept = default¶
-
template<typename T>
inline void set_value(T value)¶ Store a value.
Explicit specializations are provided for all supported native types. Because fixed-width types from
<stdint.h>are typedefs for fundamental types,dispatches to the correct specialization on every platform.set_value(my_uint32)
- Template Parameters:
T – The type to store.
- Parameters:
value – Value to store.
-
void set_value(double value, double tolerance)¶
Store a double with an explicit tolerance.
- Parameters:
value – Value to store.
tolerance – Maximum allowed difference when comparing.
-
void set_memory_buffer(const unsigned char *value, size_t size)¶
Store a raw memory buffer (not copied).
- Parameters:
value – Pointer to the buffer.
size – Size in bytes.
-
void set_const_object_pointer(StringView type, const void *object_ptr)¶
Store a const object pointer with a type name.
- Parameters:
type – Type name string, matched against comparator keys.
object_ptr – Const pointer to the object.
-
void set_object_pointer(StringView type, void *object_ptr)¶
Store a mutable object pointer with a type name.
- Parameters:
type – Type name string.
object_ptr – Pointer to the object.
-
void set_size(size_t size)¶
Set the size field (used for memory buffer parameters).
- Parameters:
size – Size in bytes.
-
void set_name(const char *name)¶
Override the name of this value.
- Parameters:
name – New name.
-
virtual bool equals(const NamedValue &p) const¶
Compare this value against
pusing the appropriate strategy.Native types are compared by value; object types use the installed NamedValueComparator. Memory buffers are compared byte-by-byte.
- Parameters:
p – Value to compare against.
- Returns:
true if the values are considered equal.
-
virtual bool compatible_for_copying(const NamedValue &p) const¶
Check whether
pcan be copied into this value.Used for output-parameter handling: ensures type compatibility before invoking the copier.
- Parameters:
p – Candidate source value.
- Returns:
true if the types are compatible for copying.
-
virtual String to_string() const¶
Return a human-readable representation of this value.
Used by the failure reporter to produce “expected X but got Y” messages.
- Returns:
Display string.
-
StringView get_type() const¶
- Returns:
The type tag string (e.g. “int”, “MyClass”, “const char*”).
-
template<typename T>
T get_value() const¶ Type-safe value accessor template.
get_value() specialization for FunctionPointerValue (
void(*)()).Explicit specializations are provided for every fundamental type and pointer type supported by the mock framework. Because fixed-width types from
<stdint.h>are typedefs for fundamental types, writingautomatically dispatches to the correct specialization on every platform.get_value<int32_t>()
const
- Template Parameters:
T – The type to retrieve.
- Returns:
The stored value converted to
T.
-
double get_double_tolerance() const¶
- Returns:
The stored double tolerance.
-
const unsigned char *get_memory_buffer() const¶
- Returns:
The stored memory buffer pointer.
-
const void *get_const_object_pointer() const¶
- Returns:
The stored const object pointer.
-
void *get_object_pointer() const¶
- Returns:
The stored mutable object pointer.
-
bool is_const_object() const¶
- Returns:
true if the stored object pointer is const.
-
size_t get_size() const¶
- Returns:
The size field (meaningful for memory buffers).
-
NamedValueComparator *get_comparator() const¶
- Returns:
The comparator installed for this value’s type, or nullptr if none was installed (native types do not need one).
-
NamedValueCopier *get_copier() const¶
- Returns:
The copier installed for this value’s type, or nullptr if none was installed.
-
template<>
void set_value(bool value)¶
-
template<>
void set_value(int value)¶
-
template<>
void set_value(unsigned int value)¶
-
template<>
void set_value(long int value)¶
-
template<>
void set_value(unsigned long int value)¶
-
template<>
void set_value(long long value)¶
-
template<>
void set_value(unsigned long long value)¶
-
template<>
void set_value(double value)¶
-
template<>
void set_value(void *value)¶
-
template<>
void set_value(const void *value)¶
-
template<>
void set_value(const char *value)¶
-
template<>
bool get_value() const¶
-
template<>
int get_value() const¶
-
template<>
unsigned int get_value() const¶
-
template<>
long int get_value() const¶
-
template<>
unsigned long int get_value() const¶
-
template<>
long long get_value() const¶
-
template<>
unsigned long long get_value() const¶
-
template<>
double get_value() const¶
-
template<>
const char *get_value() const¶
-
template<>
void *get_value() const¶
-
template<>
const void *get_value() const¶
-
template<>
inline void set_value(char v)¶
-
template<>
inline void set_value(signed char v)¶
-
template<>
inline void set_value(unsigned char v)¶
-
template<>
inline void set_value(short v)¶
-
template<>
inline void set_value(unsigned short v)¶
-
template<>
inline char get_value() const¶
-
template<>
inline signed char get_value() const¶
-
template<>
inline unsigned char get_value() const¶
-
template<>
inline short get_value() const¶
-
template<>
inline unsigned short get_value() const¶
Public Members
-
bool bool_value¶
-
int int_value¶
-
unsigned int unsigned_int_value¶
-
long int long_int_value¶
-
unsigned long int unsigned_long_int_value¶
-
long long long_long_int_value¶
-
unsigned long long unsigned_long_long_int_value¶
-
double value¶
-
double tolerance¶
-
struct mu::tiny::mock::NamedValue::[anonymous]::[anonymous] double_value¶
-
const char *string_value¶
-
void *pointer_value¶
-
const void *const_pointer_value¶
-
FunctionPointerValue function_pointer_value¶
-
const unsigned char *memory_buffer_value¶
-
const void *const_object_pointer_value¶
-
void *object_pointer_value¶
-
const void *output_pointer_value¶
Public Static Functions
-
static void set_default_comparators_and_copiers_repository(NamedValueComparatorsAndCopiersRepository *repository)¶
Replace the global repository of comparators and copiers.
- Parameters:
repository – New repository; pass nullptr to clear.
-
static NamedValueComparatorsAndCopiersRepository *get_default_comparators_and_copiers_repository()¶
[source] - Returns:
The current global comparators-and-copiers repository.
Public Static Attributes
-
static const double default_double_tolerance¶
The default tolerance used when set_value(double) is called without an explicit tolerance argument.
-
using FunctionPointerValue = void (*)()¶