Cppcheck
Classes | Public Types | Static Public Member Functions | Static Public Attributes | Friends | List of all members
MathLib Class Reference

simple math functions that uses operands stored in std::string. More...

#include <mathlib.h>

Classes

class  value
 value class More...
 

Public Types

using bigint = long long
 
using biguint = unsigned long long
 

Static Public Member Functions

static bigint toBigNumber (const std::string &str)
 for conversion of numeric literals - for atoi-like conversions please use strToInt() More...
 
static biguint toBigUNumber (const std::string &str)
 for conversion of numeric literals - for atoi-like conversions please use strToInt() More...
 
template<class T >
static std::string toString (T value)=delete
 
static double toDoubleNumber (const std::string &str)
 for conversion of numeric literals More...
 
static bool isInt (const std::string &str)
 
static bool isFloat (const std::string &str)
 
static bool isDecimalFloat (const std::string &str)
 
static bool isNegative (const std::string &str)
 
static bool isPositive (const std::string &str)
 
static bool isDec (const std::string &str)
 
static bool isFloatHex (const std::string &str)
 
static bool isIntHex (const std::string &str)
 
static bool isOct (const std::string &str)
 Does the string represent an octal number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html. More...
 
static bool isBin (const std::string &str)
 Does the string represent a binary number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html. More...
 
static std::string getSuffix (const std::string &value)
 
static bool isValidIntegerSuffix (const std::string &str, bool supportMicrosoftExtensions=true)
 Only used in unit tests. More...
 
static std::string add (const std::string &first, const std::string &second)
 
static std::string subtract (const std::string &first, const std::string &second)
 
static std::string multiply (const std::string &first, const std::string &second)
 
static std::string divide (const std::string &first, const std::string &second)
 
static std::string mod (const std::string &first, const std::string &second)
 
static std::string calculate (const std::string &first, const std::string &second, char action)
 
static std::string sin (const std::string &tok)
 
static std::string cos (const std::string &tok)
 
static std::string tan (const std::string &tok)
 
static std::string abs (const std::string &tok)
 
static bool isEqual (const std::string &first, const std::string &second)
 
static bool isNotEqual (const std::string &first, const std::string &second)
 
static bool isGreater (const std::string &first, const std::string &second)
 
static bool isGreaterEqual (const std::string &first, const std::string &second)
 
static bool isLess (const std::string &first, const std::string &second)
 
static bool isLessEqual (const std::string &first, const std::string &second)
 
static bool isNullValue (const std::string &str)
 Does the string represent the numerical value of 0? In case leading or trailing white space is provided, the function returns false. Requirement for this function: More...
 
static bool isOctalDigit (char c)
 Return true if given character is 0,1,2,3,4,5,6 or 7. More...
 
static unsigned int encodeMultiChar (const std::string &str)
 
static bool isDigitSeparator (const std::string &iCode, std::string::size_type iPos)
 
template<>
std::string toString (double value)
 
template<>
CPPCHECKLIB std::string toString (double value)
 

Static Public Attributes

static const int bigint_bits = 64
 

Friends

class TestMathLib
 

Detailed Description

simple math functions that uses operands stored in std::string.

useful when performing math on tokens.

Definition at line 33 of file mathlib.h.

Member Typedef Documentation

◆ bigint

using MathLib::bigint = long long

Definition at line 68 of file mathlib.h.

◆ biguint

using MathLib::biguint = unsigned long long

Definition at line 69 of file mathlib.h.

Member Function Documentation

◆ abs()

std::string MathLib::abs ( const std::string &  tok)
static

Definition at line 1202 of file mathlib.cpp.

References isNegative().

Referenced by SymbolDatabase::setValueTypeInTokenList().

◆ add()

std::string MathLib::add ( const std::string &  first,
const std::string &  second 
)
static

◆ calculate()

std::string MathLib::calculate ( const std::string &  first,
const std::string &  second,
char  action 
)
static

◆ cos()

std::string MathLib::cos ( const std::string &  tok)
static

Definition at line 1191 of file mathlib.cpp.

References toDoubleNumber(), and toString().

◆ divide()

std::string MathLib::divide ( const std::string &  first,
const std::string &  second 
)
static

◆ encodeMultiChar()

unsigned int MathLib::encodeMultiChar ( const std::string &  str)
static

Definition at line 360 of file mathlib.cpp.

Referenced by calculate().

◆ getSuffix()

std::string MathLib::getSuffix ( const std::string &  value)
static

◆ isBin()

bool MathLib::isBin ( const std::string &  str)
static

Does the string represent a binary number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html.

Parameters
strThe string to check. In case the string is empty, the function returns false.
Returns
Return true in case a binary number is provided and false otherwise.

Definition at line 937 of file mathlib.cpp.

References isValidIntegerSuffixIt().

Referenced by isInt(), toBigNumber(), and toBigUNumber().

◆ isDec()

bool MathLib::isDec ( const std::string &  str)
static

Definition at line 978 of file mathlib.cpp.

References isValidIntegerSuffixIt().

Referenced by isInt(), and SymbolDatabase::setValueTypeInTokenList().

◆ isDecimalFloat()

bool MathLib::isDecimalFloat ( const std::string &  str)
static

Definition at line 540 of file mathlib.cpp.

Referenced by isFloat(), and toDoubleNumber().

◆ isDigitSeparator()

bool MathLib::isDigitSeparator ( const std::string &  iCode,
std::string::size_type  iPos 
)
static
Parameters
[in]iCodeCode being considered
[in]iPosA posision within iCode
Returns
Whether iCode[iPos] is a C++14 digit separator

Definition at line 1277 of file mathlib.cpp.

◆ isEqual()

bool MathLib::isEqual ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1209 of file mathlib.cpp.

References toDoubleNumber(), and toString().

Referenced by Library::isFloatArgValid(), and isNotEqual().

◆ isFloat()

bool MathLib::isFloat ( const std::string &  str)
static

◆ isFloatHex()

bool MathLib::isFloatHex ( const std::string &  str)
static

Definition at line 847 of file mathlib.cpp.

Referenced by isFloat(), isNullValue(), and toDoubleNumber().

◆ isGreater()

bool MathLib::isGreater ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1222 of file mathlib.cpp.

References toDoubleNumber().

◆ isGreaterEqual()

bool MathLib::isGreaterEqual ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1228 of file mathlib.cpp.

References toDoubleNumber().

◆ isInt()

bool MathLib::isInt ( const std::string &  str)
static

◆ isIntHex()

bool MathLib::isIntHex ( const std::string &  str)
static

◆ isLess()

bool MathLib::isLess ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1234 of file mathlib.cpp.

References toDoubleNumber().

◆ isLessEqual()

bool MathLib::isLessEqual ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1239 of file mathlib.cpp.

References toDoubleNumber().

Referenced by CheckCondition::checkModuloAlwaysTrueFalse().

◆ isNegative()

bool MathLib::isNegative ( const std::string &  str)
static

◆ isNotEqual()

bool MathLib::isNotEqual ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1216 of file mathlib.cpp.

References isEqual().

Referenced by Library::isFloatArgValid().

◆ isNullValue()

bool MathLib::isNullValue ( const std::string &  str)
static

Does the string represent the numerical value of 0? In case leading or trailing white space is provided, the function returns false. Requirement for this function:

  • This code is allowed to be slow because of simplicity of the code.
Parameters
[in]strThe string to check. In case the string is empty, the function returns false.
Returns
Return true in case the string represents a numerical null value.

Definition at line 1253 of file mathlib.cpp.

References isFloat(), isFloatHex(), isInt(), and isIntHex().

Referenced by CheckFunctions::checkMathFunctions(), CheckOther::checkRedundantAssignment(), divide(), Scope::findFunction(), isNullOperand(), CheckFunctions::memsetInvalid2ndParam(), CheckFunctions::memsetZeroBytes(), and TemplateSimplifier::simplifyNumericCalculations().

◆ isOct()

bool MathLib::isOct ( const std::string &  str)
static

Does the string represent an octal number? In case leading or trailing white space is provided, the function returns false. Additional information can be found here: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html.

Parameters
strThe string to check. In case the string is empty, the function returns false.
Returns
Return true in case a octal number is provided and false otherwise.

Definition at line 771 of file mathlib.cpp.

References isOctalDigit(), and isValidIntegerSuffixIt().

Referenced by isInt(), toBigNumber(), and toBigUNumber().

◆ isOctalDigit()

bool MathLib::isOctalDigit ( char  c)
static

Return true if given character is 0,1,2,3,4,5,6 or 7.

Parameters
[in]cThe character to check
Returns
true if given character is octal digit.

Definition at line 1272 of file mathlib.cpp.

Referenced by isOct().

◆ isPositive()

bool MathLib::isPositive ( const std::string &  str)
static

Definition at line 643 of file mathlib.cpp.

References isNegative().

Referenced by divide(), and Tokenizer::isOneNumber().

◆ isValidIntegerSuffix()

bool MathLib::isValidIntegerSuffix ( const std::string &  str,
bool  supportMicrosoftExtensions = true 
)
static

Only used in unit tests.

Parameters
[in]strstring
[in]supportMicrosoftExtensionssupport Microsoft extension: i64
Returns
true if str is a non-empty valid integer suffix

Definition at line 755 of file mathlib.cpp.

References isValidIntegerSuffixIt().

Referenced by toBigNumber(), toBigUNumber(), and toDoubleNumber().

◆ mod()

std::string MathLib::mod ( const std::string &  first,
const std::string &  second 
)
static

Definition at line 1138 of file mathlib.cpp.

References intsuffix(), isInt(), toBigNumber(), toDoubleNumber(), and toString().

Referenced by calculate().

◆ multiply()

std::string MathLib::multiply ( const std::string &  first,
const std::string &  second 
)
static

◆ sin()

std::string MathLib::sin ( const std::string &  tok)
static

Definition at line 1185 of file mathlib.cpp.

References toDoubleNumber(), and toString().

◆ subtract()

std::string MathLib::subtract ( const std::string &  first,
const std::string &  second 
)
static

◆ tan()

std::string MathLib::tan ( const std::string &  tok)
static

Definition at line 1196 of file mathlib.cpp.

References toDoubleNumber(), and toString().

◆ toBigNumber()

MathLib::bigint MathLib::toBigNumber ( const std::string &  str)
static

◆ toBigUNumber()

MathLib::biguint MathLib::toBigUNumber ( const std::string &  str)
static

◆ toDoubleNumber()

double MathLib::toDoubleNumber ( const std::string &  str)
static

◆ toString() [1/2]

template<>
std::string MathLib::toString ( double  value)
static

Definition at line 522 of file mathlib.cpp.

References MathLib::value::str().

◆ toString() [2/2]

template<class T >
static std::string MathLib::toString ( value)
staticdelete

Friends And Related Function Documentation

◆ TestMathLib

friend class TestMathLib
friend

Definition at line 34 of file mathlib.h.

Member Data Documentation

◆ bigint_bits

const int MathLib::bigint_bits = 64
static

The documentation for this class was generated from the following files: