forked from CelestiaProject/Celestia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastroobj.cpp
More file actions
128 lines (115 loc) · 2.84 KB
/
astroobj.cpp
File metadata and controls
128 lines (115 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <celutil/debug.h>
#include <celutil/util.h>
#include "parseobject.h"
#include "astroobj.h"
#include "category.h"
void AstroObject::setIndex(AstroCatalog::IndexNumber nr)
{
if (m_mainIndexNumber != AstroCatalog::InvalidIndex)
DPRINTF(LOG_LEVEL_WARNING, "AstroObject::setIndex(%u) on object with already set index: %u!\n", nr, m_mainIndexNumber);
m_mainIndexNumber = nr;
}
Selection AstroObject::toSelection()
{
return Selection(this);
}
bool AstroObject::_addToCategory(UserCategory *c)
{
if (m_cats == nullptr)
m_cats = new CategorySet;
m_cats->insert(c);
return true;
}
bool AstroObject::addToCategory(UserCategory *c)
{
if (!_addToCategory(c))
return false;
return c->_addObject(toSelection());
}
bool AstroObject::addToCategory(const std::string &s, bool create, const std::string &d)
{
UserCategory *c = UserCategory::find(s);
if (c == nullptr)
{
if (!create)
return false;
else
c = UserCategory::newCategory(s, nullptr, d);
}
return addToCategory(c);
}
bool AstroObject::_removeFromCategory(UserCategory *c)
{
if (!isInCategory(c))
return false;
m_cats->erase(c);
if (m_cats->empty())
{
delete m_cats;
m_cats = nullptr;
}
return true;
}
bool AstroObject::removeFromCategory(UserCategory *c)
{
if (!_removeFromCategory(c))
return false;
return c->_removeObject(toSelection());
}
bool AstroObject::removeFromCategory(const std::string &s)
{
UserCategory *c = UserCategory::find(s);
if (c == nullptr)
return false;
return removeFromCategory(c);
}
bool AstroObject::clearCategories()
{
bool ret = true;
while(m_cats != nullptr)
{
UserCategory *c = *(m_cats->begin());
if (!removeFromCategory(c))
ret = false;
}
return ret;
}
bool AstroObject::isInCategory(UserCategory *c) const
{
if (m_cats == nullptr)
return false;
return m_cats->count(c) > 0;
}
bool AstroObject::isInCategory(const std::string &s) const
{
UserCategory *c = UserCategory::find(s);
if (c == nullptr)
return false;
return isInCategory(c);
}
bool AstroObject::loadCategories(Hash *hash, DataDisposition disposition, const std::string &domain)
{
if (disposition == DataDisposition::Replace)
clearCategories();
std::string cn;
if (hash->getString("Category", cn))
{
if (cn.empty())
return false;
return addToCategory(cn, true, domain);
}
Value *a = hash->getValue("Category");
if (a == nullptr)
return false;
ValueArray *v = a->getArray();
if (v == nullptr)
return false;
bool ret = true;
for (auto it : *v)
{
cn = it->getString();
if (!addToCategory(cn, true, domain))
ret = false;
}
return ret;
}