libzypp 17.37.10

zypp::iostr Namespace Reference

Iostream related utilities. More...

## Classes
class | EachLine
| Simple lineparser: Traverse each line in a file. More...

## Typedefs
using | IosFmtFlagsSaver = boost::io::ios_base_all_saver
| Save and restore streams `width`, `precision` and `fmtflags`.

## Enumerations
enum | ParseFlag { PF_LTRIM = 1 << 0 , PF_RTRIM = 1 << 1 , PF_TRIM = PF_LTRIM | PF_RTRIM , PF_SKIP_EMPTY = 1 << 2 , PF_SKIP_SHARP_COMMENT = 1 << 3 }
| simpleParseFile modifications before consuming a line. More...

## Functions
std::string | getline (std::istream &str) ZYPP_API
| Read one line from stream.
int | forEachLine (std::istream &str_r, const function< bool(int, std::string)> &consume_r) ZYPP_API
| Simple lineparser: Call functor consume_r for each line.
| BOOST_MPL_ASSERT_RELATION (int(PF_LTRIM),==, int(str::L_TRIM))
| BOOST_MPL_ASSERT_RELATION (int(PF_RTRIM),==, int(str::R_TRIM))
int | simpleParseFile (std::istream &str_r, ParseFlags flags_r, function< bool(int, std::string)> consume_r) ZYPP_API
| Simple lineparser optionally trimming and skipping comments.
std::ostream & | copy (std::istream &from_r, std::ostream &to_r)
| Copy istream to ostream.
std::ostream & | copyIndent (std::istream &from_r, std::ostream &to_r, const std::string &indent_r="> ")
| Copy istream to ostream, prefixing each line with indent_r (default "> " ).
void | tee (std::istream &from_r, std::ostream &to1_r, std::ostream &to2_r)
| Copy istream to ostream, prefixing each line with indent_r (default "> " ).
| ZYPP_DECLARE_FLAGS (ParseFlags, ParseFlag)
| ZYPP_DECLARE_OPERATORS_FOR_FLAGS (ParseFlags)
int | simpleParseFile (std::istream &str_r, function< bool(int, std::string)> consume_r)

## Detailed Description

Iostream related utilities.

## Typedef Documentation

## ◆ IosFmtFlagsSaver

using zypp::iostr::IosFmtFlagsSaver = boost::io::ios_base_all_saver

Save and restore streams `width`, `precision` and `fmtflags`.

Definition at line 36 of file IOStream.h.

## Enumeration Type Documentation

## ◆ ParseFlag

enum zypp::iostr::ParseFlag

simpleParseFile modifications before consuming a line.

Enumerator
PF_LTRIM |
PF_RTRIM |
PF_TRIM |
PF_SKIP_EMPTY |
PF_SKIP_SHARP_COMMENT |

Definition at line 189 of file IOStream.h.

## Function Documentation

## ◆ getline()

std::string zypp::iostr::getline | ( | std::istream & | str | ) |

Read one line from stream.

Reads everything up to the next newline or EOF. newline is read but not returned.

See also
  forEachLine

Definition at line 33 of file IOStream.cc.

## ◆ forEachLine()

int zypp::iostr::forEachLine | ( | std::istream & | str_r,
|  | const function< bool(int, std::string)> & | consume_r )

Simple lineparser: Call functor consume_r for each line.

Parameters

  str_r | istream to read from.
  consume_r | callback function taking linenumber and content

The loop is aborted if the callback returns `false`.

iostr::forEachLine( InputStream( "/my/file/to/read.txt" ),
[]( int num_r, std::string line_r )->bool
{
MIL << " [" num_r << "]'" << line_r << "'" << endl;
return true;
} );
zypp::InputStream
Helper to create and pass std::istream.
Definition inputstream.h:57
zypp::iostr::forEachLine
int forEachLine(std::istream &str_r, const function< bool(int, std::string)> &consume_r)
Simple lineparser: Call functor consume_r for each line.
Definition IOStream.cc:100
MIL
#define MIL
Definition Logger.h:100

Returns
  Number if lines consumed (negative if aborted by callback).

Definition at line 100 of file IOStream.cc.

## ◆ BOOST_MPL_ASSERT_RELATION() [1/2]

zypp::iostr::BOOST_MPL_ASSERT_RELATION | ( | int(PF_LTRIM) | ,
|  | int(str::L_TRIM) | )

## ◆ BOOST_MPL_ASSERT_RELATION() [2/2]

zypp::iostr::BOOST_MPL_ASSERT_RELATION | ( | int(PF_RTRIM) | ,
|  | int(str::R_TRIM) | )

## ◆ simpleParseFile() [1/2]

int zypp::iostr::simpleParseFile | ( | std::istream & | str_r,
|  | ParseFlags | flags_r,
|  | function< bool(int, std::string)> | consume_r )

Simple lineparser optionally trimming and skipping comments.

Definition at line 124 of file IOStream.cc.

## ◆ copy()

std::ostream & zypp::iostr::copy | ( | std::istream & | from_r,
|  | std::ostream & | to_r )
| inline

Copy istream to ostream.

Returns
  reference to the ostream.

Definition at line 51 of file IOStream.h.

## ◆ copyIndent()

std::ostream & zypp::iostr::copyIndent | ( | std::istream & | from_r,
|  | std::ostream & | to_r,
|  | const std::string & | indent_r = "> " )
| inline

Copy istream to ostream, prefixing each line with indent_r (default "> " ).

Returns
  reference to the ostream.

Definition at line 65 of file IOStream.h.

## ◆ tee()

void zypp::iostr::tee | ( | std::istream & | from_r,
|  | std::ostream & | to1_r,
|  | std::ostream & | to2_r )
| inline

Copy istream to ostream, prefixing each line with indent_r (default "> " ).

Returns
  reference to the ostream.

Definition at line 85 of file IOStream.h.

## ◆ ZYPP_DECLARE_FLAGS()

zypp::iostr::ZYPP_DECLARE_FLAGS | ( | ParseFlags | ,
|  | ParseFlag | )

## ◆ ZYPP_DECLARE_OPERATORS_FOR_FLAGS()

zypp::iostr::ZYPP_DECLARE_OPERATORS_FOR_FLAGS | ( | ParseFlags |  | ) |

## ◆ simpleParseFile() [2/2]

int zypp::iostr::simpleParseFile | ( | std::istream & | str_r,
|  | function< bool(int, std::string)> | consume_r )
| inline

Definition at line 204 of file IOStream.h.