~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/base/Sysconfig.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2014-01-29 22:44:28 UTC
  • Revision ID: thopiekar@googlemail.com-20140129224428-gpcqnsdakby362n8
firstĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*---------------------------------------------------------------------\
 
2
|                          ____ _   __ __ ___                          |
 
3
|                         |__  / \ / / . \ . \                         |
 
4
|                           / / \ V /|  _/  _/                         |
 
5
|                          / /__ | | | | | |                           |
 
6
|                         /_____||_| |_| |_|                           |
 
7
|                                                                      |
 
8
\---------------------------------------------------------------------*/
 
9
/** \file zypp/base/Sysconfig.h
 
10
 *
 
11
*/
 
12
#ifndef ZYPP_BASE_SYSCONFIG_H
 
13
#define ZYPP_BASE_SYSCONFIG_H
 
14
 
 
15
#include <string>
 
16
#include <map>
 
17
#include "zypp/Pathname.h"
 
18
 
 
19
namespace zypp {
 
20
  namespace base {
 
21
    namespace sysconfig {
 
22
 
 
23
      /** Read sysconfig file \a path_r and return <tt>(key,valye)</tt> pairs. */
 
24
      std::map<std::string,std::string> read( const Pathname & _path );
 
25
 
 
26
      /** Add or change a value in sysconfig file \a path_r.
 
27
       *
 
28
       * If \a key_r already exists, only the \a val_r is changed accordingly.
 
29
       *
 
30
       * In case \a key_r is not yet present in the file, a new entry may be created
 
31
       * at the end of the file, using the lines in \a newcomment_r as comment
 
32
       * block. If \a newcomment_r is not provided or empty, a new value is not
 
33
       * created and \c false is returned.
 
34
       *
 
35
       * \returns \c TRUE if an entry was changed or created.
 
36
       *
 
37
       * \throws Exception if \a path_r can not be read or written.
 
38
       *
 
39
       * \note \a val_r is written as it is. The caller is responsible for escaping and
 
40
       * enclosing in '"', in case this is needed (\see \ref writeStringVal and \ref str::escape).
 
41
       *
 
42
       * \note Lines in \a newcomment_r which do not already start with a '#',
 
43
       * are prefixes with "# ".
 
44
       *
 
45
       * \code
 
46
       *  ## Type: string
 
47
       *  ## Default: ""
 
48
       *  #
 
49
       *  # A multiline description of
 
50
       *  # the options purpose.
 
51
       *  #
 
52
       *  KEY="value"
 
53
       * \endcode
 
54
       */
 
55
      bool write( const Pathname & path_r, const std::string & key_r, const std::string & val_r,
 
56
                  const std::string & newcomment_r = std::string() );
 
57
 
 
58
      /** Convenience to add or change a string-value in sysconfig file \a path_r.
 
59
       *
 
60
       * \a val_r is expected to be a plain string value, so it is propery escaped and enclosed in
 
61
       * double quotes before it is written to the sysconfig file \a path_r.
 
62
       *
 
63
       * \see \ref write
 
64
       */
 
65
      bool writeStringVal( const Pathname & path_r, const std::string & key_r, const std::string & val_r,
 
66
                           const std::string & newcomment_r = std::string() );
 
67
 
 
68
    } // namespace sysconfig
 
69
  } // namespace base
 
70
} // namespace zypp
 
71
 
 
72
#endif // ZYPP_BASE_SYSCONFIG_H