Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

selection.h

Go to the documentation of this file.
00001 // selection.h
00002 // 
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _CELENGINE_SELECTION_H_
00011 #define _CELENGINE_SELECTION_H_
00012 
00013 #include <string>
00014 #include <celengine/star.h>
00015 #include <celengine/body.h>
00016 #include <celengine/deepskyobj.h>
00017 #include <celengine/location.h>
00018 #include <celengine/univcoord.h>
00019 
00020 class Selection
00021 {
00022  public:
00023     enum Type {
00024         Type_Nil,
00025         Type_Star,
00026         Type_Body,
00027         Type_DeepSky,
00028         Type_Location,
00029     };
00030 
00031  public:
00032     Selection() : type(Type_Nil), obj(NULL) {};
00033     Selection(Star* star) : type(Type_Star), obj(star) { checkNull(); };
00034     Selection(Body* body) : type(Type_Body), obj(body) { checkNull(); };
00035     Selection(DeepSkyObject* deepsky) : type(Type_DeepSky), obj(deepsky) {checkNull(); };
00036     Selection(Location* location) : type(Type_Location), obj(location) { checkNull(); };
00037     Selection(const Selection& sel) : type(sel.type), obj(sel.obj) {};
00038     ~Selection() {};
00039 
00040     bool empty() const { return type == Type_Nil; }
00041     double radius() const;
00042     UniversalCoord getPosition(double t) const;
00043     std::string getName() const;
00044     Selection parent() const;
00045 
00046     Star* star() const
00047     {
00048         return type == Type_Star ? static_cast<Star*>(obj) : NULL;
00049     }
00050 
00051     Body* body() const
00052     {
00053         return type == Type_Body ? static_cast<Body*>(obj) : NULL;
00054     }
00055 
00056     DeepSkyObject* deepsky() const
00057     {
00058         return type == Type_DeepSky ? static_cast<DeepSkyObject*>(obj) : NULL;
00059     }
00060 
00061     Location* location() const
00062     {
00063         return type == Type_Location ? static_cast<Location*>(obj) : NULL;
00064     }
00065 
00066     Type getType() const { return type; }
00067 
00068     // private:
00069     Type type;
00070     void* obj;
00071 
00072     void checkNull() { if (obj == NULL) type = Type_Nil; }
00073 };
00074 
00075 
00076 inline bool operator==(const Selection& s0, const Selection& s1)
00077 {
00078     return s0.type == s1.type && s0.obj == s1.obj;
00079 }
00080 
00081 inline bool operator!=(const Selection& s0, const Selection& s1)
00082 {
00083     return s0.type != s1.type || s0.obj != s1.obj;
00084 }
00085 
00086 #endif // _CELENGINE_SELECTION_H_

Generated on Sat Jan 14 22:30:28 2006 for Celestia by  doxygen 1.4.1