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 12 Bullet::Bullet() 13 : 14 fBulletData(&sEmptyBullet) 15 { 16 } 17 18 19 Bullet::Bullet(const BString& string, float spacing) 20 : 21 fBulletData(new BulletData(string, spacing), true) 22 { 23 } 24 25 26 Bullet::Bullet(const Bullet& other) 27 : 28 fBulletData(other.fBulletData) 29 { 30 } 31 32 33 Bullet& 34 Bullet::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 45 Bullet::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.Get() != NULL && other.fBulletData.Get() != NULL) 54 return *fBulletData.Get() == *other.fBulletData.Get(); 55 56 return false; 57 } 58 59 60 bool 61 Bullet::operator!=(const Bullet& other) const 62 { 63 return !(*this == other); 64 } 65 66 67 bool 68 Bullet::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& 80 Bullet::String() const 81 { 82 return fBulletData->String(); 83 } 84 85 86 bool 87 Bullet::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 99 Bullet::Spacing() const 100 { 101 return fBulletData->Spacing(); 102 } 103