fa4743ffa7f759743c84fdb60a931cd707dd7fc3
[platform/upstream/libzypp.git] / zypp / target / rpm / BinHeader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/rpm/BinHeader.h
10  *
11 */
12 #ifndef ZYPP_TARGET_RPM_BINHEADER_H
13 #define ZYPP_TARGET_RPM_BINHEADER_H
14
15 extern "C"
16 {
17 #include <stdint.h>
18 }
19
20 #include <iosfwd>
21 #include <string>
22 #include <list>
23
24 #include "zypp/base/ReferenceCounted.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/PtrTypes.h"
27 #include "zypp/target/rpm/librpm.h"
28
29 namespace zypp
30 {
31 namespace target
32 {
33 namespace rpm
34 {
35 ///////////////////////////////////////////////////////////////////
36 //
37 //      CLASS NAME : BinHeader
38 /**
39  *
40  **/
41 class BinHeader : public base::ReferenceCounted, private base::NonCopyable
42 {
43
44 public:
45
46   typedef intrusive_ptr<BinHeader> Ptr;
47
48   typedef intrusive_ptr<const BinHeader> constPtr;
49
50   typedef int32_t tag;
51
52   class intList;
53
54   class stringList;
55
56 private:
57
58   Header _h;
59
60   bool assertHeader();
61
62 public:
63
64   BinHeader( Header h_r = 0 );
65
66   /**
67    * <B>Dangerous!<\B> This one takes the header out of rhs
68    * and leaves rhs empty.
69    **/
70   BinHeader( BinHeader::Ptr & rhs );
71
72   virtual ~BinHeader();
73
74 public:
75
76   bool empty() const
77   {
78     return( _h == NULL );
79   }
80
81   bool has_tag( tag tag_r ) const;
82
83   unsigned int_list( tag tag_r, intList & lst_r ) const;
84
85   unsigned string_list( tag tag_r, stringList & lst_r ) const;
86
87   int int_val( tag tag_r ) const;
88
89   std::string string_val( tag tag_r ) const;
90
91 public:
92
93   std::list<std::string> stringList_val( tag tag_r ) const;
94
95 public:
96
97   virtual std::ostream & dumpOn( std::ostream & str ) const;
98 };
99
100 ///////////////////////////////////////////////////////////////////
101
102 ///////////////////////////////////////////////////////////////////
103 //
104 //      CLASS NAME : BinHeader::intList
105 /**
106  *
107  **/
108 class BinHeader::intList
109 {
110   intList            ( const intList & );
111   intList & operator=( const intList & );
112 private:
113   unsigned cnt;
114   void *   val;
115   tag      type;
116 private:
117   friend class BinHeader;
118   unsigned set( void * val_r, tag cnt_r, tag type_r );
119 public:
120   intList();
121   bool empty() const
122   {
123     return cnt==0;
124   }
125   unsigned size() const
126   {
127     return cnt;
128   }
129   int operator[]( const unsigned idx_r ) const;
130 };
131
132 ///////////////////////////////////////////////////////////////////
133
134 ///////////////////////////////////////////////////////////////////
135 //
136 //      CLASS NAME : BinHeader::stringList
137 /**
138  *
139  **/
140 class BinHeader::stringList
141 {
142   stringList            ( const stringList & );
143   stringList & operator=( const stringList & );
144 private:
145   unsigned cnt;
146   char **  val;
147   void clear();
148 private:
149   friend class BinHeader;
150   unsigned set( char ** val_r, tag cnt_r );
151 public:
152   stringList();
153   ~stringList()
154   {
155     clear();
156   }
157   bool empty() const
158   {
159     return cnt==0;
160   }
161   unsigned size() const
162   {
163     return cnt;
164   }
165   std::string operator[]( const unsigned idx_r ) const;
166 };
167
168 ///////////////////////////////////////////////////////////////////
169
170 } // namespace rpm
171 } // namespace target
172 } // namespace zypp
173
174 #endif // ZYPP_TARGET_RPM_BINHEADER_H