~thopiekar/zypper/libzypp-manual-import

« back to all changes in this revision

Viewing changes to zypp/LanguageCode.h

  • Committer: Thomas-Karl Pietrowski
  • Date: 2015-08-15 15:59:50 UTC
  • Revision ID: thopiekar@googlemail.com-20150815155950-j66qn38efmvn289t
syncing with "changes 15.13.0 (11)"  #9a0aca7e3a21d768491b141a8ae86ef0c3fbc227
* https://github.com/openSUSE/libzypp/commit/9a0aca7e3a21d768491b141a8ae86ef0c3fbc227

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include <iosfwd>
16
16
#include <string>
17
17
 
18
 
#include "zypp/base/PtrTypes.h"
 
18
#include "zypp/IdStringType.h"
19
19
 
20
20
///////////////////////////////////////////////////////////////////
21
21
namespace zypp
22
 
{ /////////////////////////////////////////////////////////////////
23
 
 
24
 
  class LanguageCode;
25
 
  inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs );
26
 
  inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs );
27
 
 
28
 
  ///////////////////////////////////////////////////////////////////
29
 
  //
30
 
  //    CLASS NAME : LanguageCode
31
 
  //
32
 
  /** Language codes (iso639_2/iso639_1).
33
 
   *
34
 
   * In fact the class will not prevent to use a non iso language code.
35
 
   * Just a warning will appear in the log.
36
 
  */
37
 
  class LanguageCode
 
22
{
 
23
  ///////////////////////////////////////////////////////////////////
 
24
  /// \class LanguageCode
 
25
  /// \brief Language codes (iso639_2/iso639_1).
 
26
  ///
 
27
  /// In fact the class will not prevent to use a non iso language code.
 
28
  /// Just a warning will appear in the log.
 
29
  ///////////////////////////////////////////////////////////////////
 
30
  class LanguageCode : public IdStringType<LanguageCode>
38
31
  {
39
 
    friend std::ostream & operator<<( std::ostream & str, const LanguageCode & obj );
40
 
 
41
 
  public:
42
 
    /** Implementation  */
43
 
    class Impl;
44
 
 
45
 
  public:
46
 
    /** Default ctor */
 
32
  public:
 
33
    /** Default Ctor: \ref noCode */
47
34
    LanguageCode();
48
35
 
49
 
    /** Ctor taking a string. */
50
 
    explicit
51
 
    LanguageCode( const std::string & code_r );
52
 
 
53
 
    /** Dtor */
 
36
    /** Ctor from string. */
 
37
    explicit LanguageCode( IdString str_r );
 
38
 
 
39
    /** Ctor from string. */
 
40
    explicit LanguageCode( const std::string & str_r );
 
41
 
 
42
    /** Ctor from string. */
 
43
    explicit LanguageCode( const char * str_r );
 
44
 
 
45
     /** Dtor */
54
46
    ~LanguageCode();
55
47
 
56
48
  public:
57
49
    /** \name LanguageCode constants. */
58
50
    //@{
59
 
    /** No or empty code. */
 
51
    /** Empty code. */
60
52
    static const LanguageCode noCode;
 
53
    /** Last resort "en". */
 
54
    static const LanguageCode enCode;
61
55
    //@}
62
56
 
63
57
  public:
64
 
    /** Return the language code. */
65
 
    std::string code() const;
 
58
    /** Return the language code asString. */
 
59
    std::string code() const
 
60
    { return std::string(_str); }
66
61
 
67
 
    /** Return the language name; if not available the language code. */
 
62
    /** Return the translated language name; if unknown the language code. */
68
63
    std::string name() const;
69
64
 
70
 
    /** <tt>*this != noCode</tt>. */
71
 
    inline bool hasCode() const
72
 
    { return *this != noCode; }
73
 
 
74
65
  private:
75
 
    /** Pointer to implementation */
76
 
    RW_pointer<Impl> _pimpl;
 
66
    friend class IdStringType<LanguageCode>;
 
67
    IdString _str;
77
68
  };
78
 
  ///////////////////////////////////////////////////////////////////
79
 
 
80
 
  /** \relates LanguageCode Stream output */
81
 
  inline std::ostream & operator<<( std::ostream & str, const LanguageCode & obj )
82
 
  { return str << obj.code(); }
83
 
 
84
 
  /** Comparison based on string value. */
85
 
  //@{
86
 
  /** \relates LanguageCode */
87
 
  inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs ) {
88
 
    return( lhs.code() == rhs.code() );
89
 
  }
90
 
  /** \relates LanguageCode */
91
 
  inline bool operator==( const std::string & lhs, const LanguageCode & rhs ) {
92
 
    return( lhs == rhs.code() );
93
 
  }
94
 
  /** \relates LanguageCode */
95
 
  inline bool operator==( const LanguageCode & lhs, const std::string & rhs ) {
96
 
    return( lhs.code() == rhs );
97
 
  }
98
 
 
99
 
  /** \relates LanguageCode */
100
 
  inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs ) {
101
 
    return( ! operator==( lhs, rhs ) );
102
 
  }
103
 
  /** \relates LanguageCode */
104
 
  inline bool operator!=( const std::string & lhs, const LanguageCode & rhs ) {
105
 
    return( ! operator==( lhs, rhs ) );
106
 
  }
107
 
  /** \relates LanguageCode */
108
 
  inline bool operator!=( const LanguageCode & lhs, const std::string & rhs ) {
109
 
    return( ! operator==( lhs, rhs ) );
110
 
  }
111
 
  //@}
112
 
 
113
 
  /////////////////////////////////////////////////////////////////
114
69
} // namespace zypp
115
70
///////////////////////////////////////////////////////////////////
116
71
 
117
 
///////////////////////////////////////////////////////////////////
118
 
namespace std
119
 
{ /////////////////////////////////////////////////////////////////
120
 
  /** \relates zypp::LanguageCode Default order for std::container based on code string value.*/
121
 
  template<>
122
 
    inline bool less<zypp::LanguageCode>::operator()( const zypp::LanguageCode & lhs, const zypp::LanguageCode & rhs ) const
123
 
    { return lhs.code() < rhs.code(); }
124
 
  /////////////////////////////////////////////////////////////////
125
 
} // namespace std
126
 
///////////////////////////////////////////////////////////////////
 
72
ZYPP_DEFINE_ID_HASHABLE( ::zypp::LanguageCode );
 
73
 
127
74
#endif // ZYPP_LANGUAGECODE_H