BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView ::Utils Namespace Reference

Functions

MVVM_MODEL_EXPORT std::string DoubleToString (double input, int precision=12)
 Returns string representation of double with given precision. More...
 
bool is_binary (const std::string &filename)
 Returns true if file is binary. More...
 
bool is_text (const std::string &filename)
 Returns true if file is text/ascii. More...
 
MVVM_MODEL_EXPORT std::vector< double > ParseSpaceSeparatedDoubles (const std::string &str)
 Parses string for double values and returns result as a vector. More...
 
MVVM_MODEL_EXPORT void ParseSpaceSeparatedDoubles (const std::string &str, std::vector< double > &result)
 Parses string for double values and stores result in a vector. More...
 
MVVM_MODEL_EXPORT std::string RemoveRepeatedSpaces (std::string str)
 Removes repeating spaces for a string. More...
 
MVVM_MODEL_EXPORT std::string ScientificDoubleToString (double input, int precision=6)
 Returns string representation of scientific double. More...
 
MVVM_MODEL_EXPORT std::vector< std::string > SplitString (const std::string &str, const std::string &delimeter)
 Split string on substring using given delimeter. Reproduces Python's str.split() behavior. More...
 
MVVM_MODEL_EXPORT std::optional< double > StringToDouble (const std::string &str)
 Converts string to double value using classc locale and returns it in the form of optional. More...
 
MVVM_MODEL_EXPORT std::optional< int > StringToInteger (const std::string &str)
 Converts string to integer. More...
 
MVVM_MODEL_EXPORT std::string TrimWhitespace (const std::string &str)
 Returns string after trimming whitespace surrounding, including tabs and carriage returns. More...
 

Function Documentation

◆ DoubleToString()

MVVM_MODEL_EXPORT std::string ModelView ::Utils::DoubleToString ( double  input,
int  precision = 12 
)

Returns string representation of double with given precision.

Provides additional formatting on top of iomanip, so "double x{0}" becomes "0.0".

Referenced by TEST_F().

◆ is_binary()

MVVM_MODEL_EXPORT bool ModelView ::Utils::ModelView::Utils::is_binary ( const std::string &  filename)

Returns true if file is binary.

Definition at line 33 of file binutils.cpp.

34 {
35  int buffer[BYTE_LENGTH];
36 
37  // get buffer size
38  int buffer_size = get_buffer_size(filename);
39  if (buffer_size == 0)
40  return false;
41 
42  // buffer allocation
43  get_buffer_data(filename, buffer, buffer_size);
44 
45  // control character check
46  for (int count = 0; count < buffer_size; ++count)
47  if (is_control_char(buffer[count]))
48  return true;
49 
50  return null_check(buffer, buffer_size);
51 }
#define BYTE_LENGTH
Definition: binutils.cpp:22
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")

References BYTE_LENGTH, and FileSystemUtils::filename().

Referenced by is_text(), TEST_F(), and gui2::ImportFileWidget::validateForBinaryFiles().

Here is the call graph for this function:

◆ is_text()

MVVM_MODEL_EXPORT bool ModelView ::Utils::ModelView::Utils::is_text ( const std::string &  filename)

Returns true if file is text/ascii.

Definition at line 53 of file binutils.cpp.

54 {
55 
56  return (!is_binary(filename));
57 }
bool is_binary(const std::string &filename)
Returns true if file is binary.
Definition: binutils.cpp:33

References FileSystemUtils::filename(), and is_binary().

Referenced by TEST_F().

Here is the call graph for this function:

◆ ParseSpaceSeparatedDoubles() [1/2]

MVVM_MODEL_EXPORT std::vector<double> ModelView ::Utils::ParseSpaceSeparatedDoubles ( const std::string &  str)

Parses string for double values and returns result as a vector.

All non-numeric symbols are ingored.

Referenced by TEST_F().

◆ ParseSpaceSeparatedDoubles() [2/2]

MVVM_MODEL_EXPORT void ModelView ::Utils::ParseSpaceSeparatedDoubles ( const std::string &  str,
std::vector< double > &  result 
)

Parses string for double values and stores result in a vector.

All non-numeric symbols are ingored.

◆ RemoveRepeatedSpaces()

MVVM_MODEL_EXPORT std::string ModelView ::Utils::RemoveRepeatedSpaces ( std::string  str)

Removes repeating spaces for a string.

Referenced by gui2::Utils::CreateSeparatorBasedSplitter(), and TEST_F().

◆ ScientificDoubleToString()

MVVM_MODEL_EXPORT std::string ModelView ::Utils::ScientificDoubleToString ( double  input,
int  precision = 6 
)

Returns string representation of scientific double.

Provides additional formatting on top of iomanip, so "double x{1}" becomes "1.0e+00".

Referenced by TEST_F().

◆ SplitString()

MVVM_MODEL_EXPORT std::vector<std::string> ModelView ::Utils::SplitString ( const std::string &  str,
const std::string &  delimeter 
)

Split string on substring using given delimeter. Reproduces Python's str.split() behavior.

Referenced by gui2::Utils::CreateSeparatorBasedSplitter(), gui2::Utils::ExpandLineNumberPattern(), and TEST_F().

◆ StringToDouble()

MVVM_MODEL_EXPORT std::optional<double> ModelView ::Utils::StringToDouble ( const std::string &  str)

Converts string to double value using classc locale and returns it in the form of optional.

Requires that string represents exactly one double and contains no other literals. Empty spaces at the beginning and end of the string are still allowed.

Referenced by gui2::Utils::ExtractTwoColumns(), and TEST_F().

◆ StringToInteger()

MVVM_MODEL_EXPORT std::optional<int> ModelView ::Utils::StringToInteger ( const std::string &  str)

Converts string to integer.

Requires that string represents exactly one integer and no extra symbols are defined. Empty spaces at the beginning and end of the string are still allowed.

Referenced by gui2::Utils::ExpandLineNumberPattern(), and TEST_F().

◆ TrimWhitespace()

MVVM_MODEL_EXPORT std::string ModelView ::Utils::TrimWhitespace ( const std::string &  str)

Returns string after trimming whitespace surrounding, including tabs and carriage returns.

Referenced by gui2::Utils::CreateSeparatorBasedSplitter(), and TEST_F().