1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
18 #define IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
19 
20 #include <ostream>
21 #include <memory>
22 #include <string>
23 
24 #include "androidfw/AssetManager2.h"
25 #include "idmap2/Idmap.h"
26 
27 namespace android {
28 
29 class ApkAssets;
30 
31 namespace idmap2 {
32 
33 class RawPrintVisitor : public Visitor {
34  public:
RawPrintVisitor(std::ostream & stream)35   explicit RawPrintVisitor(std::ostream& stream) : stream_(stream), offset_(0) {
36   }
37   ~RawPrintVisitor() override = default;
38   void visit(const Idmap& idmap) override;
39   void visit(const IdmapHeader& header) override;
40   void visit(const IdmapData& data) override;
41   void visit(const IdmapData::Header& header) override;
42 
43  private:
44   void print(uint8_t value, const char* fmt, ...);
45   void print(uint16_t value, const char* fmt, ...);
46   void print(uint32_t value, const char* fmt, ...);
47   void print(const std::string& value, bool print_value, const char* fmt, ...);
48   void align();
49   void pad(size_t padding);
50 
51   std::ostream& stream_;
52   size_t offset_;
53   std::unique_ptr<TargetResourceContainer> target_;
54   std::unique_ptr<OverlayResourceContainer> overlay_;
55 };
56 
57 }  // namespace idmap2
58 }  // namespace android
59 
60 #endif  // IDMAP2_INCLUDE_IDMAP2_RAWPRINTVISITOR_H_
61