/usr/include/x86_64-linux-gnu/zypp/KVMap.h is in libzypp-dev 15.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | /*---------------------------------------------------------------------\
| |
| __ __ ____ _____ ____ |
| \ \ / /_ _/ ___|_ _|___ \ |
| \ V / _` \___ \ | | __) | |
| | | (_| |___) || | / __/ |
| |_|\__,_|____/ |_| |_____| |
| |
| core system |
| (C) SuSE Linux AG |
\----------------------------------------------------------------------/
File: KVMap.h
Author: Michael Andres <ma@suse.de>
Maintainer: Michael Andres <ma@suse.de>
Purpose: Convenience stuff for handling (key,value) pairs
/-*/
#ifndef KVMap_h
#define KVMap_h
#include <iosfwd>
#include <vector>
#include <map>
#include "zypp/base/String.h"
namespace zypp {
namespace kvmap {
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KVMapBase::KVMapPolicy
/**
* @short KVMapPolicy for conversion of KVMaps to/from string.
*
* <b>_kvsplit</b>: The string separating key from value
*
* <b>_fsplit</b>: (key,value) pairs are separated by any nonempty
* sequence of characers occurring in _fsplit
*
* <b>_kvjoin</b>: The string used to join key and value.
*
* <b>_fjoin</b>: The string used to separate (key,value) pairs.
*
* TODO: Maybe options for exact _fsplit handling and timming of values.
*
**/
struct KVMapPolicy {
std::string _kvsplit;
std::string _fsplit;
std::string _kvjoin;
std::string _fjoin;
KVMapPolicy( const std::string & kvsplit_r, const std::string & fsplit_r )
: _kvsplit( kvsplit_r )
, _fsplit ( fsplit_r )
, _kvjoin ( _kvsplit )
, _fjoin ( _fsplit )
{}
KVMapPolicy( const std::string & kvsplit_r, const std::string & fsplit_r,
const std::string & kvjoin_r )
: _kvsplit( kvsplit_r )
, _fsplit ( fsplit_r )
, _kvjoin ( kvjoin_r )
, _fjoin ( _fsplit )
{}
KVMapPolicy( const std::string & kvsplit_r, const std::string & fsplit_r,
const std::string & kvjoin_r, const std::string & fjoin_r )
: _kvsplit( kvsplit_r )
, _fsplit ( fsplit_r )
, _kvjoin ( kvjoin_r )
, _fjoin ( fjoin_r )
{}
};
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KVMapBase
/**
* @short Base class for KVMaps, (key,value) pairs
**/
struct KVMapBase : public std::map<std::string,std::string> {
/**
* (key,value) map type
**/
typedef std::map<std::string,std::string> map_type;
KVMapBase()
{}
KVMapBase( const map_type & kvmap_r )
: std::map<std::string,std::string>( kvmap_r )
{}
/**
* Test whether key is set.
**/
bool has( const std::string & key_r ) const {
return( find( key_r ) != end() );
}
/**
* @short KVMapPolicy for KVMaps using a single char as separator (e.g. mount options).
**/
template<char kv, char f>
struct CharSep : public KVMapPolicy { CharSep() : KVMapPolicy( std::string(1,kv), std::string(1,f) ) {} };
///////////////////////////////////////////////////////////////////
/**
* Split str_r into (key,value) map, using the separators defined
* by opts_r.
**/
static map_type split( const std::string & str_r,
const KVMapPolicy & opts_r ) {
map_type ret;
std::vector<std::string> fields;
str::split( str_r, std::back_inserter(fields), opts_r._fsplit );
for ( unsigned i = 0; i < fields.size(); ++i ) {
std::string::size_type pos = fields[i].find( opts_r._kvsplit );
if ( pos == std::string::npos ) {
ret[fields[i]] = "";
} else {
ret[fields[i].substr( 0, pos )] = fields[i].substr( pos+1 );
}
}
return ret;
}
/**
* Join (key,value) map into string, using the separators defined
* by opts_r.
**/
static std::string join( const map_type & kvmap_r,
const KVMapPolicy & opts_r ) {
std::string ret;
for ( map_type::const_iterator it = kvmap_r.begin(); it != kvmap_r.end(); ++it ) {
if ( ! ret.empty() ) {
ret += opts_r._fjoin;
}
ret += it->first;
if ( !it->second.empty() ) {
ret += opts_r._kvjoin + it->second;
}
}
return ret;
}
};
} // namespace kvmap
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : KVMap<KVMapOpts>
/**
* @short A map of (key,value) strings.
*
* The template argument defines the @ref kvmap::Options for
* split and join.
*
* E.g. mount options (a comma separated list of key[=value] pairs)
* could be handled by KVMap<kvmap::KVMapBase::Comma>.
**/
template<typename KVMapOpts>
struct KVMap : public kvmap::KVMapBase {
KVMap()
{}
KVMap( const char * str_r )
: kvmap::KVMapBase( split( (str_r?str_r:""), KVMapOpts() ) )
{}
KVMap( const std::string & str_r )
: kvmap::KVMapBase( split( str_r, KVMapOpts() ) )
{}
KVMap( const map_type & map_r )
: kvmap::KVMapBase( map_r )
{}
~KVMap() {}
std::string asString() const {
return join( *this, KVMapOpts() );
}
};
///////////////////////////////////////////////////////////////////
template<typename KVMapOpts>
std::ostream & operator<<( std::ostream & str, const KVMap<KVMapOpts> & obj )
{ return str << obj.asString(); }
///////////////////////////////////////////////////////////////////
} // namespace zypp
#endif // KVMap_h
|