libzypp 17.31.23
zypp::iostr Namespace Reference

Iostream related utilities. More...

Classes

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

Typedefs

typedef boost::io::ios_base_all_saver IosFmtFlagsSaver
 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)
 Read one line from stream.
 
int forEachLine (std::istream &str_r, function< bool(int, std::string)> consume_r)
 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)
 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

typedef boost::io::ios_base_all_saver zypp::iostr::IosFmtFlagsSaver

Save and restore streams width, precision and fmtflags.

Definition at line 35 of file IOStream.h.

Enumeration Type Documentation

◆ ParseFlag

simpleParseFile modifications before consuming a line.

Enumerator
PF_LTRIM 
PF_RTRIM 
PF_TRIM 
PF_SKIP_EMPTY 
PF_SKIP_SHARP_COMMENT 

Definition at line 188 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,
function< bool(int, std::string)>  consume_r 
)

Simple lineparser: Call functor consume_r for each line.

Parameters
str_ristream to read from.
consume_rcallback 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;
} );
Helper to create and pass std::istream.
Definition: inputstream.h:57
int forEachLine(std::istream &str_r, function< bool(int, std::string)> consume_r)
Simple lineparser: Call functor consume_r for each line.
Definition: IOStream.cc:100
#define MIL
Definition: Logger.h:96
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 50 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 64 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 84 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 203 of file IOStream.h.