1 /* 2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 #include "Bullet.h" 7 8 9 static BulletData sEmptyBullet; 10 11 Bullet()12Bullet::Bullet() 13 : 14 fBulletData(&sEmptyBullet) 15 { 16 } 17 18 Bullet(const BString & string,float spacing)19Bullet::Bullet(const BString& string, float spacing) 20 : 21 fBulletData(new BulletData(string, spacing), true) 22 { 23 } 24 25 Bullet(const Bullet & other)26Bullet::Bullet(const Bullet& other) 27 : 28 fBulletData(other.fBulletData) 29 { 30 } 31 32 33 Bullet& operator =(const Bullet & other)34Bullet::operator=(const Bullet& other) 35 { 36 if (this == &other) 37 return *this; 38 39 fBulletData = other.fBulletData; 40 return *this; 41 } 42 43 44 bool operator ==(const Bullet & other) const45Bullet::operator==(const Bullet& other) const 46 { 47 if (this == &other) 48 return true; 49 50 if (fBulletData == other.fBulletData) 51 return true; 52 53 if (fBulletData.IsSet() && other.fBulletData.IsSet()) 54 return *fBulletData == *other.fBulletData; 55 56 return false; 57 } 58 59 60 bool operator !=(const Bullet & other) const61Bullet::operator!=(const Bullet& other) const 62 { 63 return !(*this == other); 64 } 65 66 67 bool SetString(const BString & string)68Bullet::SetString(const BString& string) 69 { 70 BulletDataRef data = fBulletData->SetString(string); 71 if (data == fBulletData) 72 return data->String() == string; 73 74 fBulletData = data; 75 return true; 76 } 77 78 79 const BString& String() const80Bullet::String() const 81 { 82 return fBulletData->String(); 83 } 84 85 86 bool SetSpacing(float spacing)87Bullet::SetSpacing(float spacing) 88 { 89 BulletDataRef data = fBulletData->SetSpacing(spacing); 90 if (data == fBulletData) 91 return data->Spacing() == spacing; 92 93 fBulletData = data; 94 return true; 95 } 96 97 98 float Spacing() const99Bullet::Spacing() const 100 { 101 return fBulletData->Spacing(); 102 } 103