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 #include "sync/api/attachments/attachment_id.h" 6 7 #include "base/logging.h" 8 #include "sync/internal_api/public/base/attachment_id_proto.h" 9 #include "sync/protocol/sync.pb.h" 10 11 namespace syncer { 12 InitializeWrapper(Wrapper * wrapper)13void AttachmentId::ImmutableAttachmentIdProtoTraits::InitializeWrapper( 14 Wrapper* wrapper) { 15 *wrapper = new sync_pb::AttachmentIdProto(); 16 } 17 DestroyWrapper(Wrapper * wrapper)18void AttachmentId::ImmutableAttachmentIdProtoTraits::DestroyWrapper( 19 Wrapper* wrapper) { 20 delete *wrapper; 21 } 22 23 const sync_pb::AttachmentIdProto& Unwrap(const Wrapper & wrapper)24AttachmentId::ImmutableAttachmentIdProtoTraits::Unwrap(const Wrapper& wrapper) { 25 return *wrapper; 26 } 27 28 sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper * wrapper)29AttachmentId::ImmutableAttachmentIdProtoTraits::UnwrapMutable( 30 Wrapper* wrapper) { 31 return *wrapper; 32 } 33 Swap(sync_pb::AttachmentIdProto * t1,sync_pb::AttachmentIdProto * t2)34void AttachmentId::ImmutableAttachmentIdProtoTraits::Swap( 35 sync_pb::AttachmentIdProto* t1, 36 sync_pb::AttachmentIdProto* t2) { 37 t1->Swap(t2); 38 } 39 ~AttachmentId()40AttachmentId::~AttachmentId() {} 41 operator ==(const AttachmentId & other) const42bool AttachmentId::operator==(const AttachmentId& other) const { 43 return proto_.Get().unique_id() == other.proto_.Get().unique_id(); 44 } 45 operator !=(const AttachmentId & other) const46bool AttachmentId::operator!=(const AttachmentId& other) const { 47 return !operator==(other); 48 } 49 operator <(const AttachmentId & other) const50bool AttachmentId::operator<(const AttachmentId& other) const { 51 return proto_.Get().unique_id() < other.proto_.Get().unique_id(); 52 } 53 54 // Static. Create()55AttachmentId AttachmentId::Create() { 56 sync_pb::AttachmentIdProto proto = CreateAttachmentIdProto(); 57 return AttachmentId(&proto); 58 } 59 60 // Static. CreateFromProto(const sync_pb::AttachmentIdProto & proto)61AttachmentId AttachmentId::CreateFromProto( 62 const sync_pb::AttachmentIdProto& proto) { 63 sync_pb::AttachmentIdProto copy_of_proto(proto); 64 return AttachmentId(©_of_proto); 65 } 66 GetProto() const67const sync_pb::AttachmentIdProto& AttachmentId::GetProto() const { 68 return proto_.Get(); 69 } 70 AttachmentId(sync_pb::AttachmentIdProto * proto)71AttachmentId::AttachmentId(sync_pb::AttachmentIdProto* proto) 72 : proto_(proto) {} 73 74 } // namespace syncer 75