scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
aid.cpp
Go to the documentation of this file.
1#include "./aid.hpp"
2
3#include "boost/algorithm/string.hpp"
4
5#include <iostream>
6#include <sstream>
7#include <vector>
8
9using namespace std;
10
11namespace scifir
12{
13 aid::aid() : universe(),galaxy(),solar_system(),astronomical_body(),astronomical_type(aid::NONE)
14 {}
15
16 aid::aid(const aid& x) : universe(x.universe),galaxy(x.galaxy),solar_system(x.solar_system),astronomical_body(x.astronomical_body),astronomical_type(x.astronomical_type)
17 {}
18
19 aid::aid(aid&& x) : universe(std::move(x.universe)),galaxy(std::move(x.galaxy)),solar_system(std::move(x.solar_system)),astronomical_body(std::move(x.astronomical_body)),astronomical_type(std::move(x.astronomical_type))
20 {}
21
22 aid::aid(const scifir::astronomical_body& predefined_astronomical_body) : aid()
23 {
24 if (predefined_astronomical_body != astronomical_body::NONE)
25 {
26 universe = "universe";
27 }
28 if (predefined_astronomical_body == astronomical_body::MILKY_WAY)
29 {
30 galaxy = "milky-way";
32 }
33 else if (predefined_astronomical_body == astronomical_body::ANDROMEDA)
34 {
35 galaxy = "andromeda";
37 }
38 else if (predefined_astronomical_body == astronomical_body::SOLAR_SYSTEM)
39 {
40 galaxy = "milky-way";
41 solar_system = "solar-system";
43 }
44 else if (predefined_astronomical_body == astronomical_body::SUN)
45 {
46 galaxy = "milky-way";
47 solar_system = "solar-system";
48 astronomical_body = "sun";
50 }
51 else if (predefined_astronomical_body == astronomical_body::MOON)
52 {
53 galaxy = "milky-way";
54 solar_system = "solar-system";
55 astronomical_body = "moon";
57 }
58 else if (predefined_astronomical_body == astronomical_body::MERCURY)
59 {
60 galaxy = "milky-way";
61 solar_system = "solar-system";
62 astronomical_body = "mercury";
64 }
65 else if (predefined_astronomical_body == astronomical_body::VENUS)
66 {
67 galaxy = "milky-way";
68 solar_system = "solar-system";
69 astronomical_body = "venus";
71 }
72 else if (predefined_astronomical_body == astronomical_body::EARTH)
73 {
74 galaxy = "milky-way";
75 solar_system = "solar-system";
76 astronomical_body = "earth";
78 }
79 else if (predefined_astronomical_body == astronomical_body::MARS)
80 {
81 galaxy = "milky-way";
82 solar_system = "solar-system";
83 astronomical_body = "mars";
85 }
86 else if (predefined_astronomical_body == astronomical_body::JUPITER)
87 {
88 galaxy = "milky-way";
89 solar_system = "solar-system";
90 astronomical_body = "jupiter";
92 }
93 else if (predefined_astronomical_body == astronomical_body::SATURN)
94 {
95 galaxy = "milky-way";
96 solar_system = "solar-system";
97 astronomical_body = "saturn";
99 }
100 else if (predefined_astronomical_body == astronomical_body::URANUS)
101 {
102 galaxy = "milky-way";
103 solar_system = "solar-system";
104 astronomical_body = "uranus";
106 }
107 else if (predefined_astronomical_body == astronomical_body::NEPTUNE)
108 {
109 galaxy = "milky-way";
110 solar_system = "solar-system";
111 astronomical_body = "neptune";
113 }
114 else if (predefined_astronomical_body == astronomical_body::CERES)
115 {
116 galaxy = "milky-way";
117 solar_system = "solar-system";
118 astronomical_body = "ceres";
120 }
121 else if (predefined_astronomical_body == astronomical_body::ORCUS)
122 {
123 galaxy = "milky-way";
124 solar_system = "solar-system";
125 astronomical_body = "orcus";
127 }
128 else if (predefined_astronomical_body == astronomical_body::PLUTO)
129 {
130 galaxy = "milky-way";
131 solar_system = "solar-system";
132 astronomical_body = "pluto";
134 }
135 else if (predefined_astronomical_body == astronomical_body::HAUMEA)
136 {
137 galaxy = "milky-way";
138 solar_system = "solar-system";
139 astronomical_body = "haumea";
141 }
142 else if (predefined_astronomical_body == astronomical_body::QUAOAR)
143 {
144 galaxy = "milky-way";
145 solar_system = "solar-system";
146 astronomical_body = "quaoar";
148 }
149 else if (predefined_astronomical_body == astronomical_body::MAKEMAKE)
150 {
151 galaxy = "milky-way";
152 solar_system = "solar-system";
153 astronomical_body = "makemake";
155 }
156 else if (predefined_astronomical_body == astronomical_body::GONGGONG)
157 {
158 galaxy = "milky-way";
159 solar_system = "solar-system";
160 astronomical_body = "gonggong";
162 }
163 else if (predefined_astronomical_body == astronomical_body::ERIS)
164 {
165 galaxy = "milky-way";
166 solar_system = "solar-system";
167 astronomical_body = "eris";
169 }
170 else if (predefined_astronomical_body == astronomical_body::SEDNA)
171 {
172 galaxy = "milky-way";
173 solar_system = "solar-system";
174 astronomical_body = "sedna";
176 }
177 else if (predefined_astronomical_body == astronomical_body::IO)
178 {
179 galaxy = "milky-way";
180 solar_system = "solar-system";
181 astronomical_body = "io";
183 }
184 else if (predefined_astronomical_body == astronomical_body::EUROPA)
185 {
186 galaxy = "milky-way";
187 solar_system = "solar-system";
188 astronomical_body = "europa";
190 }
191 else if (predefined_astronomical_body == astronomical_body::GANYMEDE)
192 {
193 galaxy = "milky-way";
194 solar_system = "solar-system";
195 astronomical_body = "ganymede";
197 }
198 else if (predefined_astronomical_body == astronomical_body::CALLISTO)
199 {
200 galaxy = "milky-way";
201 solar_system = "solar-system";
202 astronomical_body = "callisto";
204 }
205 else if (predefined_astronomical_body == astronomical_body::MIMAS)
206 {
207 galaxy = "milky-way";
208 solar_system = "solar-system";
209 astronomical_body = "mimas";
211 }
212 else if (predefined_astronomical_body == astronomical_body::ENCELADUS)
213 {
214 galaxy = "milky-way";
215 solar_system = "solar-system";
216 astronomical_body = "enceladus";
218 }
219 else if (predefined_astronomical_body == astronomical_body::TETHYS)
220 {
221 galaxy = "milky-way";
222 solar_system = "solar-system";
223 astronomical_body = "tethys";
225 }
226 else if (predefined_astronomical_body == astronomical_body::DIONE)
227 {
228 galaxy = "milky-way";
229 solar_system = "solar-system";
230 astronomical_body = "dione";
232 }
233 else if (predefined_astronomical_body == astronomical_body::RHEA)
234 {
235 galaxy = "milky-way";
236 solar_system = "solar-system";
237 astronomical_body = "rhea";
239 }
240 else if (predefined_astronomical_body == astronomical_body::TITAN)
241 {
242 galaxy = "milky-way";
243 solar_system = "solar-system";
244 astronomical_body = "titan";
246 }
247 else if (predefined_astronomical_body == astronomical_body::IAPETUS)
248 {
249 galaxy = "milky-way";
250 solar_system = "solar-system";
251 astronomical_body = "iapetus";
253 }
254 else if (predefined_astronomical_body == astronomical_body::MIRANDA)
255 {
256 galaxy = "milky-way";
257 solar_system = "solar-system";
258 astronomical_body = "miranda";
260 }
261 else if (predefined_astronomical_body == astronomical_body::ARIEL)
262 {
263 galaxy = "milky-way";
264 solar_system = "solar-system";
265 astronomical_body = "ariel";
267 }
268 else if (predefined_astronomical_body == astronomical_body::UMBRIEL)
269 {
270 galaxy = "milky-way";
271 solar_system = "solar-system";
272 astronomical_body = "umbriel";
274 }
275 else if (predefined_astronomical_body == astronomical_body::TITANIA)
276 {
277 galaxy = "milky-way";
278 solar_system = "solar-system";
279 astronomical_body = "titania";
281 }
282 else if (predefined_astronomical_body == astronomical_body::OBERON)
283 {
284 galaxy = "milky-way";
285 solar_system = "solar-system";
286 astronomical_body = "oberon";
288 }
289 else if (predefined_astronomical_body == astronomical_body::TRITON)
290 {
291 galaxy = "milky-way";
292 solar_system = "solar-system";
293 astronomical_body = "triton";
295 }
296 else if (predefined_astronomical_body == astronomical_body::CHARON)
297 {
298 galaxy = "milky-way";
299 solar_system = "solar-system";
300 astronomical_body = "charon";
302 }
303 else if (predefined_astronomical_body == astronomical_body::DYSNOMIA)
304 {
305 galaxy = "milky-way";
306 solar_system = "solar-system";
307 astronomical_body = "dysnomia";
309 }
310 }
311
312 aid::aid(const aid::type& new_astronomical_type,const string& new_astro1,const string& new_astro2,const string& new_astro3,const string& new_astro4) : universe(),galaxy(),solar_system(),astronomical_body(),astronomical_type(aid::NONE)
313 {
314 if (new_astronomical_type == aid::UNIVERSE)
315 {
316 universe = new_astro1;
318 }
319 else if (new_astronomical_type == aid::GALAXY)
320 {
321 if (new_astro2 != "")
322 {
323 universe = new_astro2;
324 }
325 else
326 {
327 universe = "universe";
328 }
329 galaxy = new_astro1;
331 }
332 else if (new_astronomical_type == aid::SOLAR_SYSTEM)
333 {
334 if (new_astro3 != "")
335 {
336 universe = new_astro3;
337 }
338 else
339 {
340 universe = "universe";
341 }
342 galaxy = new_astro1;
343 solar_system = new_astro2;
345 }
346 else if (new_astronomical_type != aid::UNIVERSE and new_astronomical_type != aid::GALAXY and new_astronomical_type != aid::SOLAR_SYSTEM and new_astronomical_type != aid::NONE)
347 {
348 if (new_astro4 != "")
349 {
350 universe = new_astro4;
351 }
352 else
353 {
354 universe = "universe";
355 }
356 galaxy = new_astro1;
357 solar_system = new_astro2;
358 astronomical_body = new_astro3;
359 astronomical_type = new_astronomical_type;
360 }
361 }
362
363 aid::aid(const string& init_aid) : aid()
364 {
365 initialize_from_string(init_aid);
366 }
367
369 {
370 universe = x.universe;
371 galaxy = x.galaxy;
375 return *this;
376 }
377
379 {
380 universe = std::move(x.universe);
381 galaxy = std::move(x.galaxy);
382 solar_system = std::move(x.solar_system);
383 astronomical_body = std::move(x.astronomical_body);
384 astronomical_type = std::move(x.astronomical_type);
385 return *this;
386 }
387
388 aid& aid::operator =(const string& init_aid)
389 {
390 initialize_from_string(init_aid);
391 return *this;
392 }
393
395 {
396 return (universe == "no-universe");
397 }
398
400 {
401 return (universe == "unknown-universe");
402 }
403
405 {
406 return (galaxy == "no-galaxy");
407 }
408
410 {
411 return (galaxy == "unknown-galaxy");
412 }
413
415 {
416 return (solar_system == "unknown-solar-system");
417 }
418
420 {
421 return (solar_system == "no-solar-system");
422 }
423
425 {
426 return (astronomical_body == "unknown-planet");
427 }
428
430 {
431 return (astronomical_body == "unknown-moon");
432 }
433
435 {
436 return (astronomical_body == "unknown-star");
437 }
438
440 {
441 return (astronomical_body == "unknown-asteroid");
442 }
443
444 void aid::initialize_from_string(const string& init_aid)
445 {
446 vector<string> values;
447 boost::split(values,init_aid,boost::is_any_of(":"));
448 string aid_type;
449 if (values[0].front() == '(' and isalpha(values[0][1]))
450 {
451 string new_value1;
452 if (isalpha(values[0][2]))
453 {
454 astronomical_type = create_astronomical_type(values[0].substr(1,2));
455 if (values[0].at(4) != ' ')
456 {
457 new_value1 = values[0].substr(4);
458 }
459 else
460 {
461 new_value1 = values[0].substr(5);
462 }
463 }
464 else
465 {
466 astronomical_type = create_astronomical_type(values[0].substr(1,1));
467 if (values[0].at(3) != ' ')
468 {
469 new_value1 = values[0].substr(3);
470 }
471 else
472 {
473 new_value1 = values[0].substr(4);
474 }
475 }
477 {
478 if (values.size() == 4)
479 {
480 universe = new_value1;
481 galaxy = values[1];
482 solar_system = values[2];
483 astronomical_body = values[3];
484 }
485 else if (values.size() == 3)
486 {
487 universe = "universe";
488 galaxy = new_value1;
489 solar_system = values[1];
490 astronomical_body = values[2];
491 }
492 else
493 {
495 }
496 }
498 {
499 if (values.size() == 3)
500 {
501 universe = new_value1;
502 galaxy = values[1];
503 solar_system = values[2];
504 }
505 else if (values.size() == 2)
506 {
507 universe = "universe";
508 galaxy = new_value1;
509 solar_system = values[1];
510 }
511 else
512 {
514 }
515 }
516 else if (astronomical_type == aid::GALAXY)
517 {
518 if (values.size() == 2)
519 {
520 universe = new_value1;
521 galaxy = values[1];
522 }
523 else if (values.size() == 1)
524 {
525 universe = "universe";
526 galaxy = new_value1;
527 }
528 else
529 {
531 }
532 }
534 {
535 universe = new_value1;
536 }
537 }
538 }
539
540 string aid::display() const
541 {
543 {
544 ostringstream out;
545 out << "(" << to_string(astronomical_type) << ") ";
547 {
548 out << universe;
549 }
550 else if (astronomical_type == aid::GALAXY)
551 {
552 if (universe != "" and universe != "universe")
553 {
554 out << universe << ":";
555 }
556 out << galaxy;
557 }
559 {
560 if (universe != "" and universe != "universe")
561 {
562 out << universe << ":";
563 }
564 out << galaxy << ":" << solar_system;
565 }
566 else
567 {
568 if (universe != "" and universe != "universe")
569 {
570 out << universe << ":";
571 }
572 out << galaxy << ":" << solar_system << ":" << astronomical_body;
573 }
574 return out.str();
575 }
576 else
577 {
578 return "";
579 }
580 }
581
582 string to_string(const aid& x)
583 {
584 return x.display();
585 }
586
587 string to_string(const aid::type& x)
588 {
589 switch (x)
590 {
591 case aid::UNIVERSE:
592 return "U";
593 case aid::GALAXY:
594 return "G";
596 return "SS";
597 case aid::PLANET:
598 return "P";
599 case aid::STAR:
600 return "ST";
601 case aid::ASTEROID:
602 return "A";
603 case aid::MOON:
604 return "MN";
605 case aid::METEOR:
606 return "MT";
607 case aid::NONE:
608 return "";
609 }
610 return "";
611 }
612
613 aid::type create_astronomical_type(const string& astronomical_type_abbreviation)
614 {
615 if (astronomical_type_abbreviation == "U")
616 {
617 return aid::UNIVERSE;
618 }
619 else if (astronomical_type_abbreviation == "G")
620 {
621 return aid::GALAXY;
622 }
623 else if (astronomical_type_abbreviation == "SS")
624 {
625 return aid::SOLAR_SYSTEM;
626 }
627 else if (astronomical_type_abbreviation == "P")
628 {
629 return aid::PLANET;
630 }
631 else if (astronomical_type_abbreviation == "ST")
632 {
633 return aid::STAR;
634 }
635 else if (astronomical_type_abbreviation == "A")
636 {
637 return aid::ASTEROID;
638 }
639 else if (astronomical_type_abbreviation == "MN")
640 {
641 return aid::MOON;
642 }
643 else if (astronomical_type_abbreviation == "MT")
644 {
645 return aid::METEOR;
646 }
647 else
648 {
649 return aid::NONE;
650 }
651 }
652}
653
654bool operator ==(const scifir::aid& x, const scifir::aid& y)
655{
657 {
658 return true;
659 }
660 else
661 {
662 return false;
663 }
664}
665
666bool operator !=(const scifir::aid& x, const scifir::aid& y)
667{
668 return !(x == y);
669}
670
671bool operator ==(const scifir::aid& x, const string& init_aid)
672{
673 scifir::aid y = scifir::aid(init_aid);
674 return (x == y);
675}
676
677bool operator !=(const scifir::aid& x, const string& init_aid)
678{
679 return !(x == init_aid);
680}
681
682bool operator ==(const string& init_aid, const scifir::aid& x)
683{
684 scifir::aid y = scifir::aid(init_aid);
685 return (x == y);
686}
687
688bool operator !=(const string& init_aid, const scifir::aid& x)
689{
690 return !(init_aid == x);
691}
692
693void operator +=(string& x, const scifir::aid& y)
694{
695 ostringstream output;
696 output << y;
697 x += output.str();
698}
699
700string operator +(const string& x, const scifir::aid& y)
701{
702 ostringstream output;
703 output << x;
704 output << y;
705 return output.str();
706}
707
708string operator +(const scifir::aid& y, const string& x)
709{
710 ostringstream output;
711 output << y;
712 output << x;
713 return output.str();
714}
715
716ostream& operator <<(ostream& os, const scifir::aid& x)
717{
718 return os << to_string(x);
719}
720
721istream& operator >>(istream& is, scifir::aid& x)
722{
723 char a[256];
724 is.getline(a, 256);
725 string b(a);
726 boost::trim(b);
727 x = scifir::aid(b);
728 return is;
729}
bool operator==(const scifir::aid &x, const scifir::aid &y)
Returns true if the type and all data are the same between x and y.
Definition aid.cpp:654
istream & operator>>(istream &is, scifir::aid &x)
Allows that an istream initializes by string an aid x.
Definition aid.cpp:721
void operator+=(string &x, const scifir::aid &y)
Concatenates the string representation of aid y to the string x.
Definition aid.cpp:693
bool operator!=(const scifir::aid &x, const scifir::aid &y)
Returns true if the type or any data is different between x and y.
Definition aid.cpp:666
ostream & operator<<(ostream &os, const scifir::aid &x)
Adds the string representation of the aid x to an output stream os.
Definition aid.cpp:716
string operator+(const string &x, const scifir::aid &y)
Concatenates x with the string representation of aid y.
Definition aid.cpp:700
Class that stores astronomical ids, not as an integer but with an string as identifier....
Definition aid.hpp:14
bool has_unknown_asteroid() const
Returns true if the asteroid has the special value "unknown-asteroid".
Definition aid.cpp:439
string universe
The universe of the astronomical body. The predefined value no-universe means that there's no univers...
Definition aid.hpp:42
void initialize_from_string(const string &init_aid)
Internal function. Initializes the member-variables with an initialization string of aid.
Definition aid.cpp:444
bool has_unknown_solar_system() const
Returns true if the solar system has the special value "unknown-solar-system".
Definition aid.cpp:414
bool has_unknown_star() const
Returns true if the star has the special value "unknown-star".
Definition aid.cpp:434
string galaxy
The galaxy of the astronomical body. The predefined value no-galaxy means that the astronomical objec...
Definition aid.hpp:43
aid::type astronomical_type
The type of the astronomical body, which can be any value of the enum aid::type.
Definition aid.hpp:46
bool has_no_solar_system() const
Definition aid.cpp:419
string solar_system
The solar system of the astronomical body. The predefined value no-solar-system means that the astron...
Definition aid.hpp:44
bool has_unknown_planet() const
Returns true if the planet has the special value "unknown-planet".
Definition aid.cpp:424
bool has_unknown_galaxy() const
Returns true if the galaxy has the special value "unknown-galaxy".
Definition aid.cpp:409
string display() const
Returns a string representation of aid.
Definition aid.cpp:540
aid & operator=(const aid &x)
Copy assignment. The member-variables are copied from the aid x.
Definition aid.cpp:368
bool has_unknown_universe() const
Returns true if the universe has the special value "unknown-universe".
Definition aid.cpp:399
aid()
Default constructor. The astronomical type is NONE, the other member-variables are empty strings.
Definition aid.cpp:13
bool has_unknown_moon() const
Returns true if the moon has the special value "unknown-moon".
Definition aid.cpp:429
bool has_no_galaxy() const
Definition aid.cpp:404
type
Type of astronomical body.
Definition aid.hpp:16
@ NONE
No astronomical body.
Definition aid.hpp:16
@ MOON
A moon. A moon is a natural satellite of a planet. His string representation is MN.
Definition aid.hpp:16
@ ASTEROID
An asteroid. An asteroid is an astronomical object that orbits another astronomical object....
Definition aid.hpp:16
@ METEOR
A meteor. His string representation is MT.
Definition aid.hpp:16
@ GALAXY
A galaxy. His string representation is G.
Definition aid.hpp:16
@ SOLAR_SYSTEM
A solar system. A solar system is composed of planets orbiting a star. His string representation is S...
Definition aid.hpp:16
@ UNIVERSE
A universe. His string representation is U.
Definition aid.hpp:16
@ STAR
A star. His string representation is ST.
Definition aid.hpp:16
@ PLANET
A planet. A planet is an astronomical object with atmosphere. His string representation is P.
Definition aid.hpp:16
bool has_no_universe() const
Definition aid.cpp:394
string astronomical_body
The name of the astronomical body. The predefined value unknown-planet means that it's not known the ...
Definition aid.hpp:45
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
astronomical_body
Contains predefined astronomical bodies to be set automatically in the aid class. All of them are imp...
Definition aid.hpp:11
@ IAPETUS
The moon of Saturn Iapetus.
@ DYSNOMIA
The moon of Eris Dysnomia.
@ ENCELADUS
The moon of Saturn Enceladus.
@ MILKY_WAY
The Milky Way galaxy.
@ MIMAS
The moon of Saturn Mimas.
@ CERES
The dwarf planet Ceres.
@ OBERON
The moon of Uranus Oberon.
@ RHEA
The moon of Saturn Rhea.
@ ANDROMEDA
The Andromeda galaxy, 2.5 million light years from Earth.
@ GANYMEDE
The moon of Jupiter Ganymede.
@ EUROPA
The moon of Jupiter Europa.
@ TITANIA
The moon of Uranus Titania.
@ SATURN
The planet Saturn.
@ MARS
The planet Mars.
@ HAUMEA
The dwarf planet Haumea.
@ MIRANDA
The moon of Uranus Miranda.
@ UMBRIEL
The moon of Uranus Umbriel.
@ QUAOAR
The dwarf planet Quaoar.
@ URANUS
The planet Uranus.
@ TITAN
The moon of Saturn Titan.
@ ERIS
The dwarf planet Eris.
@ GONGGONG
The possible dwarf planet Gonggong.
@ SUN
The Sun, the sun of the solar system of the Earth.
@ TRITON
The moon of Neptune Triton.
@ VENUS
The planet Venus.
@ ARIEL
The moon of Uranus Ariel.
@ JUPITER
The planet Jupiter.
@ NEPTUNE
The planet Neptune.
@ SEDNA
The minor body Sedna.
@ CALLISTO
The moon of Jupiter Callisto.
@ MERCURY
The planet Mercury.
@ TETHYS
The moon of Saturn Tethys.
@ NONE
No predefined astronomical body selected.
@ EARTH
The planet Earth.
@ DIONE
The moon of Saturn Dione.
@ CHARON
The moon of Pluto Charon.
@ PLUTO
The dwarf planet Pluto.
@ MAKEMAKE
The dwarf planet Makemake.
@ MOON
The Moon of the Earth.
@ IO
The moon of Jupiter Io.
@ ORCUS
The possible dwarf planet Orcus.
@ SOLAR_SYSTEM
The Solar System of the Earth.
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
aid::type create_astronomical_type(const string &astronomical_type_abbreviation)
Creates an instance of an aid::type with the given string, which is the reverse as the to_string() fu...
Definition aid.cpp:613