Wt: Wt::any_traits< Type > Struct Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
Wt::any_traits< Type > Struct Template Reference
Model/view system

A traits class for a type stored in a cpp17::any. More...

`#include <WAny.h>`

## Static Public Member Functions
static WString | asString (const Type &value, const WString &format)
| Converts a value to a string.
static double | asNumber (const Type &v)
| Converts a value to a number.
static int | compare (const Type &v1, const Type &v2)
| Compares two values.

## Detailed Description

template<typename Type>
struct Wt::any_traits< Type >

A traits class for a type stored in a cpp17::any.

The traits are used by Wt's view classes (such as Wt::WTableView Wt::WTreeView, Wt::Chart::WCartesianChart) to deal with values in a Wt::WAbstractItemModel:

- conversion to a string by Wt::asString()
- conversion to a number by Wt::asNumber()
- sorting by Wt::WSortFilterProxyModel or WStandardItemModel.

This traits class provides a default implementation for supporting values value of a custom type Type in Wt's MVC system, which relies on:

- serializing to a stream (std::ostream << value) for converting the value to a string.
- lexical interpretation as a number for converting the value to a number, using std::stod()
- sorting using operator== and operator<

You can specialize these traits if you need to customize one or more of these operations.

## Member Function Documentation

## ◆ asNumber()

template<typename Type >

double Wt::any_traits< Type >::asNumber | ( | const Type & | v | ) |
| static

Converts a value to a number.

The default implementation uses std::stod() on the string value

## ◆ asString()

template<typename Type >

WString Wt::any_traits< Type >::asString | ( | const Type & | value,
|  | const WString & | format )
| static

Converts a value to a string.

The default implementation uses std::ostream<< operator for the value.

## ◆ compare()

template<typename Type >

int Wt::any_traits< Type >::compare | ( | const Type & | v1,
|  | const Type & | v2 )
| static

Compares two values.

The default implementation uses operator== and operator<.