UNPKG

1.42 kBtext/x-cView Raw
1#pragma once
2
3#ifdef ERROR
4#define ERROR_ ERROR
5#undef ERROR
6#endif
7
8#include <stdint.h> // node < 7 uses libstdc++ on macOS which lacks complete c++11
9#include <string>
10
11namespace BMPParser{
12 enum Status{
13 EMPTY,
14 OK,
15 ERROR,
16 };
17
18 class Parser{
19 public:
20 Parser()=default;
21 ~Parser();
22 void parse(uint8_t *buf, int bufSize, uint8_t *format=nullptr);
23 void clearImgd();
24 int32_t getWidth() const;
25 int32_t getHeight() const;
26 uint8_t *getImgd() const;
27 Status getStatus() const;
28 std::string getErrMsg() const;
29
30 private:
31 Status status = Status::EMPTY;
32 uint8_t *data = nullptr;
33 uint8_t *ptr = nullptr;
34 int len = 0;
35 int32_t w = 0;
36 int32_t h = 0;
37 uint8_t *imgd = nullptr;
38 std::string err = "";
39 std::string op = "";
40
41 template <typename T, bool check=true> inline T get();
42 template <typename T, bool check=true> inline T get(uint8_t* pointer);
43 std::string getStr(int len, bool reverse=false);
44 inline void skip(int len);
45 void calcMaskShift(uint32_t& shift, uint32_t& mask, double& multp);
46
47 void setOp(std::string val);
48 std::string getOp() const;
49
50 void setErrUnsupported(std::string msg);
51 void setErrUnknown(std::string msg);
52 void setErr(std::string msg);
53 std::string getErr() const;
54 };
55}
56
57#ifdef ERROR_
58#define ERROR ERROR_
59#undef ERROR_
60#endif