KiCad PCB EDA Suite
Loading...
Searching...
No Matches
database_value.h File Reference
#include <cstdint>
#include <string>
#include <variant>

Go to the source code of this file.

Typedefs

using DB_VALUE = std::variant<std::monostate, std::string, int64_t, double, bool>
 A single database cell, where monostate is SQL NULL.
 

Functions

std::string DatabaseValueToString (const DB_VALUE &aValue)
 Convert a database value to the text KiCad stores for it.
 
std::string DatabaseValueToString (const char *)=delete
 A C string would silently convert to bool, so the caller must build a std::string.
 
std::string NormalizeDecimalText (const std::string &aText)
 Trim redundant trailing zeros and a dangling decimal point from decimal text, for example "4700000.0000" becomes "4700000", and add the missing zero to ".5".
 

Typedef Documentation

◆ DB_VALUE

using DB_VALUE = std::variant<std::monostate, std::string, int64_t, double, bool>

A single database cell, where monostate is SQL NULL.

Definition at line 28 of file database_value.h.

Function Documentation

◆ DatabaseValueToString() [1/2]

std::string DatabaseValueToString ( const char * )
delete

A C string would silently convert to bool, so the caller must build a std::string.

◆ DatabaseValueToString() [2/2]

std::string DatabaseValueToString ( const DB_VALUE & aValue)

Convert a database value to the text KiCad stores for it.

Doubles use the shortest text that reads back to the same value, booleans become "1" or "0" and NULL becomes an empty string. Strings are returned unchanged.

Definition at line 59 of file database_value.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), DATABASE_CONNECTION::makeRow(), and DATABASE_CONNECTION::readAndCache().

◆ NormalizeDecimalText()

std::string NormalizeDecimalText ( const std::string & aText)

Trim redundant trailing zeros and a dangling decimal point from decimal text, for example "4700000.0000" becomes "4700000", and add the missing zero to ".5".

A leading sign is kept except that a zero value with a decimal point becomes "0". Text without a decimal point or that is not plain decimal is returned unchanged.

Definition at line 25 of file database_value.cpp.

References result.

Referenced by BOOST_AUTO_TEST_CASE(), and decodeRow().