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
9static BulletData sEmptyBullet;
10
11
12Bullet::Bullet()
13	:
14	fBulletData(&sEmptyBullet)
15{
16}
17
18
19Bullet::Bullet(const BString& string, float spacing)
20	:
21	fBulletData(new BulletData(string, spacing), true)
22{
23}
24
25
26Bullet::Bullet(const Bullet& other)
27	:
28	fBulletData(other.fBulletData)
29{
30}
31
32
33Bullet&
34Bullet::operator=(const Bullet& other)
35{
36	if (this == &other)
37		return *this;
38
39	fBulletData = other.fBulletData;
40	return *this;
41}
42
43
44bool
45Bullet::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
60bool
61Bullet::operator!=(const Bullet& other) const
62{
63	return !(*this == other);
64}
65
66
67bool
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
79const BString&
80Bullet::String() const
81{
82	return fBulletData->String();
83}
84
85
86bool
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
98float
99Bullet::Spacing() const
100{
101	return fBulletData->Spacing();
102}
103