libzypp  17.1.1
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. More...
 

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. More...
 
int forEachLine (std::istream &str_r, function< bool(int, std::string)> consume_r)
 Simple lineparser: Call functor consume_r for each line. More...
 
 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. More...
 
std::ostream & copy (std::istream &from_r, std::ostream &to_r)
 Copy istream to ostream. More...
 
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 "> " ). More...
 
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 "> " ). More...
 
 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;
} );
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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 203 of file IOStream.h.