~ubuntu-branches/ubuntu/trusty/mkvtoolnix/trusty

« back to all changes in this revision

Viewing changes to src/common/amf.h

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2013-01-21 09:04:27 UTC
  • mfrom: (1.1.18) (4.2.26 sid)
  • Revision ID: package-import@ubuntu.com-20130121090427-5c9d0gyf2807ju9d
Tags: 6.0.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   mkvmerge -- utility for splicing together matroska files
 
3
   from component media subtypes
 
4
 
 
5
   Distributed under the GPL
 
6
   see the file COPYING for details
 
7
   or visit http://www.gnu.org/copyleft/gpl.html
 
8
 
 
9
   helper functions for AMF (Action Message Format) data
 
10
 
 
11
   Written by Moritz Bunkus <moritz@bunkus.org>.
 
12
*/
 
13
 
 
14
#ifndef MTX_COMMON_AMF_H
 
15
#define MTX_COMMON_AMF_H
 
16
 
 
17
#include "common/common_pch.h"
 
18
 
 
19
#include <unordered_map>
 
20
#include <boost/variant.hpp>
 
21
 
 
22
namespace mtx { namespace amf {
 
23
 
 
24
typedef boost::variant<double, bool, std::string> value_type_t;
 
25
typedef std::unordered_map<std::string, value_type_t> meta_data_t;
 
26
 
 
27
class value_to_string_c: public boost::static_visitor<std::string> {
 
28
public:
 
29
  std::string operator ()(double value) const {
 
30
    return (boost::format("%1%") % value).str();
 
31
  }
 
32
 
 
33
  std::string operator ()(bool value) const {
 
34
    return value ? "yes" : "no";
 
35
  }
 
36
 
 
37
  std::string operator ()(std::string const &value) const {
 
38
    return value;
 
39
  }
 
40
};
 
41
 
 
42
class script_parser_c {
 
43
public:
 
44
  typedef enum {
 
45
    TYPE_NUMBER      = 0x00,
 
46
    TYPE_BOOL        = 0x01,
 
47
    TYPE_STRING      = 0x02,
 
48
    TYPE_OBJECT      = 0x03,
 
49
    TYPE_MOVIECLIP   = 0x04,
 
50
    TYPE_NULL        = 0x05,
 
51
    TYPE_UNDEFINED   = 0x06,
 
52
    TYPE_REFERENCE   = 0x07,
 
53
    TYPE_ECMAARRAY   = 0x08,
 
54
    TYPE_OBJECT_END  = 0x09,
 
55
    TYPE_ARRAY       = 0x0a,
 
56
    TYPE_DATE        = 0x0b,
 
57
    TYPE_LONG_STRING = 0x0c,
 
58
  } data_type_e;
 
59
 
 
60
private:
 
61
  memory_cptr m_data_mem;
 
62
  mm_mem_io_c m_data;
 
63
  meta_data_t m_meta_data;
 
64
  bool m_in_meta_data;
 
65
  unsigned int m_level;
 
66
 
 
67
  bool m_debug;
 
68
 
 
69
public:
 
70
  script_parser_c(memory_cptr const &mem);
 
71
 
 
72
  bool parse();
 
73
  meta_data_t const &get_meta_data() const;
 
74
 
 
75
  template<typename T>
 
76
  T const *
 
77
  get_meta_data_value(std::string const &key) {
 
78
    auto itr = m_meta_data.find(key);
 
79
    if (m_meta_data.end() == itr)
 
80
      return nullptr;
 
81
 
 
82
    return boost::get<T>(&itr->second);
 
83
  }
 
84
 
 
85
protected:
 
86
  std::string read_string(data_type_e type);
 
87
  std::pair<value_type_t, bool> read_value();
 
88
  void read_properties(std::unordered_map<std::string, value_type_t> &properties);
 
89
  std::string level_spacer() const;
 
90
};
 
91
 
 
92
}}
 
93
 
 
94
namespace std {
 
95
template <>
 
96
struct hash<mtx::amf::script_parser_c::data_type_e> {
 
97
  size_t operator()(mtx::amf::script_parser_c::data_type_e value) const {
 
98
    return hash<unsigned int>()(static_cast<unsigned int>(value));
 
99
  }
 
100
};
 
101
}
 
102
 
 
103
#endif  // MTX_COMMON_H