1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Map.h
11 #ifndef ZYPP_SAT_MAP_H
12 #define ZYPP_SAT_MAP_H
21 #include "zypp/base/PtrTypes.h"
23 ///////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 /// \brief Libsolv (bit)Map wrapper.
33 /// \Note Requested sizes are filled up to the next multiple of eight.
34 /// Libsolv bitmaps are not shrinkable.
35 ///////////////////////////////////////////////////////////////////
39 typedef unsigned long size_type;
41 /** Type to indicate the bitmap should match the current pools capacity. */
42 struct PoolSizeType {};
43 /** An object indicating the bitmap should match the current pools capacity. */
44 static constexpr PoolSizeType poolSize = PoolSizeType();
47 /** Default ctor: empty Map */
50 /** Ctor taking the Map size */
51 explicit Map( size_type size_r );
53 /** Ctor creating a Map matching the current pools capacity */
60 /** Whether Map is empty. */
63 /** Size of the Map. */
64 size_type size() const;
66 /** Grow the Map if necessary. */
67 void grow( size_type size_r );
73 /** Clear all bits. */
76 /** Assign \c val_r to all bits. */
77 void assignAll( bool val_r );
80 * \throws std::out_of_range if \a idx_r is out of range
82 void set( size_type idx_r );
84 /** Clear bit \c idx_r.
85 * \throws std::out_of_range if \a idx_r is out of range
87 void clear( size_type idx_r );
89 /** Assign \c val_r to bit \c idx_r.
90 * \throws std::out_of_range if \a idx_r is out of range
92 void assign( size_type idx_r, bool val_r );
95 /** Test bit \c idx_r.
96 * \throws std::out_of_range if \a idx_r is out of range
98 bool test( size_type idx_r ) const;
100 /** Test bit \c idx_r.
101 * \throws std::out_of_range if \a idx_r is out of range
103 bool operator[]( size_type idx_r ) const
104 { return test( idx_r ); }
107 /** String representation */
108 std::string asString( const char on_r = '1', const char off_r = '0' ) const;
111 operator struct ::_Map *(); ///< libsolv backdoor
112 operator const struct ::_Map *() const ///< libsolv backdoor
113 { return _pimpl.get(); }
115 RWCOW_pointer<struct ::_Map> _pimpl; ///< Pointer to implementation
118 /** \relates Map Stream output */
119 inline std::ostream & operator<<( std::ostream & str, const Map & obj )
120 { return str << obj.asString(); }
123 bool operator==( const Map & lhs, const Map & rhs );
126 inline bool operator!=( const Map & lhs, const Map & rhs )
127 { return !( lhs == rhs ); }
130 ///////////////////////////////////////////////////////////////////
132 /** \relates Map Clone function for RWCOW_pointer */
133 template<> struct ::_Map * rwcowClone<struct ::_Map>( const struct ::_Map * rhs );
135 typedef sat::Map Bitmap;
138 ///////////////////////////////////////////////////////////////////
139 #endif // ZYPP_SAT_MAP_H