1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_APP_INFO_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_APP_INFO_H_ // NOLINT 3 4 #include <memory> 5 #include <string> 6 #include <unordered_map> 7 8 #include "dynamic_depth/element.h" 9 #include "dynamic_depth/item.h" 10 #include "xmpmeta/xml/deserializer.h" 11 #include "xmpmeta/xml/serializer.h" 12 13 namespace dynamic_depth { 14 15 /** 16 * A AppInfo element for a Dynamic Depth device. 17 */ 18 class AppInfo : public Element { 19 public: 20 // Appends child elements' namespaces' and their respective hrefs to the 21 // given collection, and any parent nodes' names to prefix_names. 22 // Key: Name of the namespace. 23 // Value: Full namespace URL. 24 // Example: ("AppInfo", "http://ns.google.com/photos/dd/1.0/appinfo/") 25 void GetNamespaces( 26 std::unordered_map<string, string>* ns_name_href_map) override; 27 28 // Serializes this object. 29 bool Serialize( 30 ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override; 31 32 // Creates an AppInfo from the given fields. Returns null if the version 33 // field is empty and [item_uri is empty and items is null]. 34 // Params' descriptions: 35 // application is the name of the application that created the content. 36 // version is the application's version for the content. 37 // data is the optional payload associated with the given app. If this field 38 // is not empty but item_uri is empty or items is null, then the data will 39 // not be serialized. 40 // item_uri is the Container URI of the file that contains the content. 41 // application, and at least one of version or item_uri, must not be 42 // empty. 43 // items is the list of items where the serialized data is stored. It is the 44 // caller's responsibility to use items to construct a Container, and 45 // ensure that it is serialized along with this Image element. Data will 46 // not be serialized if this field is null. 47 static std::unique_ptr<AppInfo> FromData( 48 const string& application, const string& version, const string& data, 49 const string& item_uri, std::vector<std::unique_ptr<Item>>* items); 50 51 // Returns the deserialized AppInfo; null if parsing fails. 52 static std::unique_ptr<AppInfo> FromDeserializer( 53 const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer, 54 const string& namespace_str); 55 56 // Getters. 57 const string& GetApplication() const; 58 const string& GetVersion() const; 59 const string& GetItemUri() const; 60 61 // Disallow copying. 62 AppInfo(const AppInfo&) = delete; 63 void operator=(const AppInfo&) = delete; 64 65 private: 66 AppInfo(); 67 68 bool ParseFields( 69 const ::dynamic_depth::xmpmeta::xml::Deserializer& deserializer); 70 71 // Required. 72 string application_; 73 74 // At least one of version or item_uri must be present. 75 string version_; 76 string item_uri_; 77 }; 78 79 } // namespace dynamic_depth 80 81 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_APP_INFO_H_ // NOLINT 82