Clingo
Loading...
Searching...
No Matches
CppClingo::FormatSpec Struct Reference

Format specification for a field. More...

#include <fstring.hh>

Public Types

enum class  Conversion : uint8_t { str = 0 , repr = 1 }
 Enumeration of conversion options. More...
 
enum class  Align : uint8_t {
  none , left , right , number ,
  center
}
 The alignment options. More...
 
enum class  Sign : uint8_t { plus , minus , space }
 The sign options. More...
 
enum class  Grouping : uint8_t { none , comma , underscore }
 Enumeration of grouping options. More...
 
enum class  Type : uint8_t {
  character , binary , octal , decimal ,
  hex_lower , hex_upper , locale , string
}
 Enumeration of type options. More...
 

Public Member Functions

 FormatSpec ()=default
 Construct a default format specification.
 
auto hash () const -> size_t
 Compute the hash of the format specification.
 

Static Public Member Functions

static auto build (SymbolStore &store, std::string_view str) -> std::optional< FormatSpec >
 Parse a format specification from a string.
 

Public Attributes

std::vector< std::variant< SharedString, size_t > > accessors
 The vector of accessors.
 
uint32_t width = 0
 The width of the field.
 
std::optional< char > fill
 The fill character for padding if the field is wider than the content.
 
Type type = Type::string
 The type of the field.
 
Grouping grouping = Grouping::none
 The grouping option.
 
Conversion conversion = Conversion::str
 The conversion option.
 
Align align = Align::none
 The alignment of the field.
 
Sign sign = Sign::minus
 The sign option.
 
bool alternate_form = false
 Whether to use the alternate form.
 

Friends

auto operator== (FormatSpec const &a, FormatSpec const &b) -> bool=default
 Compare two format specifications for equality.
 
auto operator<=> (FormatSpec const &a, FormatSpec const &b) -> std::strong_ordering=default
 Compare two format specifications.
 
auto operator<< (std::ostream &out, FormatSpec const &spec) -> std::ostream &
 Output the format specification to a stream.
 
auto operator<< (Util::OutputBuffer &out, FormatSpec const &spec) -> Util::OutputBuffer &
 Output the format specification to a stream.
 

Detailed Description

Format specification for a field.

Member Enumeration Documentation

◆ Align

enum class CppClingo::FormatSpec::Align : uint8_t
strong

The alignment options.

Enumerator
none 

No alignment specified (see defaults below).

left 

Use left alignment (default for non-numbers).

right 

Use right alignment (default for numbers).

number 

Use number alignment (sign to the left/number to the right).

center 

Use center alignment.

◆ Conversion

enum class CppClingo::FormatSpec::Conversion : uint8_t
strong

Enumeration of conversion options.

If the string representation of a symbol is used, clingo strings are printed without quotes and with special characters.

Enumerator
str 

Use the string representation of a symbol.

repr 

Use the clingo representation of a symbol.

◆ Grouping

enum class CppClingo::FormatSpec::Grouping : uint8_t
strong

Enumeration of grouping options.

Enumerator
comma 

Do not use thousands separator (default).

underscore 

Use comma as thousands separator.

◆ Sign

enum class CppClingo::FormatSpec::Sign : uint8_t
strong

The sign options.

Enumerator
plus 

Use an explicit plus sign for positive numbers.

minus 

Use a minus sign for negative numbers only (default).

space 

Use a space for positive numbers.

◆ Type

enum class CppClingo::FormatSpec::Type : uint8_t
strong

Enumeration of type options.

Enumerator
character 

Output the character with the given integer code.

binary 

OUtput an integer in binary format.

octal 

Output an integer in octal format.

decimal 

Output an integer in decimal format.

hex_lower 

Output an integer in hexadecimal format with lower-case letters.

hex_upper 

Output an integer in hexadecimal format with upper-case letters.

locale 

Output an integer using the locale's conventions.

string 

Output symbol using their default string representation (default).

Member Function Documentation

◆ build()

static auto CppClingo::FormatSpec::build ( SymbolStore store,
std::string_view  str 
) -> std::optional< FormatSpec >
static

Parse a format specification from a string.

A format specification has the following syntax:

spec ::= variable(accessor*)[[fill]align][sign]["#"]"][width][grouping][type]
variable ::= <clingo variable>
accessor ::= "." <clingo identifier> | "[" <unsigned number> "]"
fill ::= <any character>
align ::= "<" | ">" | "=" | "^"
sign ::= "+" | "-" | " "
width ::= <unsigned number>
grouping ::= "," | "_"
type ::= "b" | "c" | "d" | "o" | "x" | "X" | "n" | "s"
Sign sign
The sign option.
Definition fstring.hh:110
Align align
The alignment of the field.
Definition fstring.hh:108
std::optional< char > fill
The fill character for padding if the field is wider than the content.
Definition fstring.hh:100

Member Data Documentation

◆ accessors

std::vector<std::variant<SharedString, size_t> > CppClingo::FormatSpec::accessors

The vector of accessors.

One can for exmaples use [0].name to refer to g in the term f(g(1),2).


The documentation for this struct was generated from the following file: