OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | |
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <set> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "sync/base/sync_export.h" | |
16 #include "sync/internal_api/public/util/immutable.h" | |
17 | |
18 namespace sync_pb { | |
19 class AttachmentIdProto; | |
20 } // namespace sync_pb | |
21 | |
22 namespace syncer { | |
23 | |
24 // Uniquely identifies an attachment. | |
25 // | |
26 // Two attachments with equal (operator==) AttachmentIds are considered | |
27 // equivalent. | |
28 class SYNC_EXPORT AttachmentId { | |
29 public: | |
30 AttachmentId(const AttachmentId& other); | |
31 ~AttachmentId(); | |
32 | |
33 // Default copy and assignment are welcome. | |
34 | |
35 bool operator==(const AttachmentId& other) const; | |
36 | |
37 bool operator!=(const AttachmentId& other) const; | |
38 | |
39 // Needed for using AttachmentId as key in std::map. | |
40 bool operator<(const AttachmentId& other) const; | |
41 | |
42 // Creates a unique id for an attachment. | |
43 // | |
44 // |size| is the attachment's size in bytes. | |
45 // | |
46 // |crc32c| is the attachment's crc32c. | |
47 static AttachmentId Create(size_t size, uint32_t crc32c); | |
48 | |
49 // Creates an attachment id from an initialized proto. | |
50 static AttachmentId CreateFromProto(const sync_pb::AttachmentIdProto& proto); | |
51 | |
52 const sync_pb::AttachmentIdProto& GetProto() const; | |
53 | |
54 // Returns the size (in bytes) the attachment. | |
55 size_t GetSize() const; | |
56 | |
57 // Returns the crc32c the attachment. | |
58 uint32_t GetCrc32c() const; | |
59 | |
60 private: | |
61 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments | |
62 // in immutable.h. | |
63 struct SYNC_EXPORT ImmutableAttachmentIdProtoTraits { | |
64 typedef sync_pb::AttachmentIdProto* Wrapper; | |
65 static void InitializeWrapper(Wrapper* wrapper); | |
66 static void DestroyWrapper(Wrapper* wrapper); | |
67 static const sync_pb::AttachmentIdProto& Unwrap(const Wrapper& wrapper); | |
68 static sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper* wrapper); | |
69 static void Swap(sync_pb::AttachmentIdProto* t1, | |
70 sync_pb::AttachmentIdProto* t2); | |
71 }; | |
72 | |
73 typedef Immutable<sync_pb::AttachmentIdProto, | |
74 ImmutableAttachmentIdProtoTraits> | |
75 ImmutableAttachmentIdProto; | |
76 | |
77 ImmutableAttachmentIdProto proto_; | |
78 | |
79 explicit AttachmentId(sync_pb::AttachmentIdProto* proto); | |
80 }; | |
81 | |
82 // All public interfaces use AttachmentIdList. AttachmentIdSet is used in | |
83 // implementations of algorithms where set properties are needed. | |
84 typedef std::vector<AttachmentId> AttachmentIdList; | |
85 typedef std::set<AttachmentId> AttachmentIdSet; | |
86 | |
87 } // namespace syncer | |
88 | |
89 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | |
OLD | NEW |