summaryrefslogtreecommitdiff
path: root/internal/xmpmeta/xml/serializer.h
blob: 9d35ad85b5f6eb6ac32f0583d4fb51854f6038a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_SERIALIZER_H_  // NOLINT
#define DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_SERIALIZER_H_  // NOLINT

#include <memory>
#include <string>
#include <vector>

#include "base/port.h"

namespace photos_editing_formats {
namespace xml {

// Serializes properties for a hierarchy of objects.
// Example:
//  BookSerializer serializer();
//  // Serialize a list of objects.
//  std::unique_ptr<Serializer> book_list_serializer =
//      serializer->CreateListSerializer("Books");
//  for (Book *book : book_list) {
//    std::unique_ptr<Serializer> book_serializer =
//        cameras_serializer->CreateItemSerializer("Book");
//    success &= book->Serialize(book_serializer.get());
//
//    // Write properties in an object.
//    // This would be called from the Book class.
//    string book_name("Book");
//    std::unique_ptr<Serializer> book_info_serializer =
//        book_serializer->CreateSerializer("Info");
//    book_info_serializer->WriteProperty("Author", "Cereal Eyser");
//    book_info_serializer->WriteProperty("ISBN", "314159265359");
//    std::unique_ptr<Serializer> genre_serializer =
//        book_serializer->CreateSeralizer("Genre", true);
//    std::unique_ptr<Serializer> fantasy_serializer =
//        genre_serializer->CreateSerialzer("Fantasy");
//    // Serialize genre properties here.
//  }

class Serializer {
 public:
  virtual ~Serializer() {}

  // Returns a Serializer for an object that is an item in a list.
  virtual std::unique_ptr<Serializer> CreateItemSerializer(
      const string& prefix, const string& item_name) const = 0;

  // Returns a Serializer for a list of objects.
  virtual std::unique_ptr<Serializer> CreateListSerializer(
      const string& prefix, const string& list_name) const = 0;

  // Creates a serializer from the current serializer.
  // node_ns_name is the XML namespace to which the newly created node belongs.
  // If this parameter is an empty string, the new node will not belong to a
  // namespace.
  // node_name is the name of the new node. This parameter cannot be an empty
  // string.
  virtual std::unique_ptr<Serializer> CreateSerializer(
      const string& node_ns_name, const string& node_name) const = 0;

  // Serializes a property with the given prefix.
  // Example: <NodeName PropertyPrefix:PropertyName="PropertyValue" />
  virtual bool WriteBoolProperty(const string& prefix, const string& name,
                                 bool value) const = 0;
  virtual bool WriteProperty(const string& prefix, const string& name,
                             const string& value) const = 0;

  // Serializes the collection of values.
  virtual bool WriteIntArray(const string& prefix, const string& array_name,
                             const std::vector<int>& values) const = 0;
  virtual bool WriteDoubleArray(const string& prefix, const string& array_name,
                                const std::vector<double>& values) const = 0;
};

}  // namespace xml
}  // namespace photos_editing_formats

#endif // DYNAMIC_DEPTH_INTERNAL_XMPMETA_XML_SERIALIZER_H_  // NOLINT