source: Sophya/trunk/SophyaLib/SkyMap/spherepos.cc@ 2479

Last change on this file since 2479 was 1967, checked in by ansari, 23 years ago

Ajout throw TypeMismatchExc ds PPersist_X::SetDataObj() ds les differents classes handler PPersist, a place du return simple, lorsque le type d'objet n'etait pas bon ... Reza 26/4/2002

File size: 3.4 KB
Line 
1// 04/01/00 : implantation de la persistance par classe deleguee - Guy Le Meur
2
3#include "spherepos.h"
4#include "datatype.h"
5#include <typeinfo>
6
7static char *head_spherepos_cc_ = "$Header: /Users/garnier/temp/CVSSophya/SophyaLib/SkyMap/spherepos.cc,v 1.2 2002-04-26 16:48:22 ansari Exp $";
8
9
10//................. SphereCoordSys class .................
11
12SphereCoordSys::SphereCoordSys(){
13 id_ = SphereCoordSys_NEUTRAL;
14 description_ = "NEUTRAL SphereCoordSystem";
15}
16SphereCoordSys::SphereCoordSys(const SphereCoordSys& a )
17{
18 id_ = a.id_;
19 description_ = a.description_;
20}
21
22SphereCoordSys::SphereCoordSys(int id, const string& description){
23 id_ = id;
24 description_ = description;
25}
26
27SphereCoordSys::~SphereCoordSys()
28{
29}
30SphereCoordSys& SphereCoordSys::operator = (const SphereCoordSys& a)
31{
32 id_ = a.id_;
33 description_ = a.description_;
34 return *this;
35}
36
37
38////////////////////////////////////////////////////////////////
39// -------------------------------------------------------------------------
40// Les objets delegues pour la gestion de persistance
41// -------------------------------------------------------------------------
42
43FIO_SphereCoordSys::FIO_SphereCoordSys()
44 {
45 dobj=new SphereCoordSys;
46 ownobj=true;
47 }
48FIO_SphereCoordSys::FIO_SphereCoordSys(string const & filename)
49 {
50 dobj=new SphereCoordSys;
51 ownobj=true;
52 Read(filename);
53 }
54FIO_SphereCoordSys::FIO_SphereCoordSys(const SphereCoordSys & obj)
55 {
56 dobj = new SphereCoordSys(obj);
57 ownobj=true;
58 }
59FIO_SphereCoordSys::FIO_SphereCoordSys(SphereCoordSys * obj)
60 {
61 dobj = obj;
62 ownobj=false;
63 }
64FIO_SphereCoordSys::~FIO_SphereCoordSys()
65 {
66 if (ownobj && dobj) delete dobj;
67 }
68AnyDataObj* FIO_SphereCoordSys::DataObj()
69 {
70 return(dobj);
71 }
72
73void FIO_SphereCoordSys::SetDataObj(AnyDataObj & o)
74{
75 SphereCoordSys * po = dynamic_cast<SphereCoordSys *>(&o);
76 if (po == NULL) {
77 char buff[160];
78 sprintf(buff,"FIO_SphereCoordSys::SetDataObj(%s) - Object type error ! ",
79 typeid(o).name());
80 throw TypeMismatchExc(PExcLongMessage(buff));
81 }
82
83 if (ownobj && dobj) delete dobj;
84 dobj = po; ownobj = false;
85}
86
87
88void FIO_SphereCoordSys::ReadSelf(PInPersist& is)
89 {
90uint_8 itab[3];
91 string description;
92is.Get(itab, 3);
93is.GetStr(description);
94if (dobj == NULL) dobj = new SphereCoordSys(itab[1], description);
95 else *dobj= SphereCoordSys(itab[1], description);
96 }
97void FIO_SphereCoordSys::WriteSelf(POutPersist& os) const
98{
99if (dobj == NULL) return; // Attention - $CHECK$ Guy 04/01/00
100// On ecrit 3 uint_8
101// 0 : Numero de version, 1 : Id, 2 reserve a l
102uint_8 itab[3];
103itab[0] = 1;
104itab[1] = dobj->Id();
105itab[2] = 0;
106os.Put(itab, 3);
107os.PutStr(dobj->description());
108}
109
110
111
112//................. SpherePosition class .................
113
114SpherePosition::SpherePosition()
115 : UnitVector()
116{
117 cs_ = new SphereCoordSys;
118}
119
120SpherePosition::SpherePosition(double theta, double phi, SphereCoordSys* cs)
121 : UnitVector(theta, phi)
122{
123if (cs == NULL) cs_ = new SphereCoordSys;
124else cs_ = cs;
125}
126
127SpherePosition::SpherePosition(double x, double y, double z, SphereCoordSys* cs)
128 : UnitVector(x, y, z)
129{
130if (cs == NULL) cs_ = new SphereCoordSys;
131else cs_ = cs;
132}
133
134SpherePosition::~SpherePosition()
135{
136if (cs_) delete cs_;
137}
138
139UnitVector SpherePosition::Transform(const SphereCoordSys& /*cs*/) const
140{
141return(*this);
142}
143
144double SpherePosition::Separation(const SpherePosition& gamma) const
145{
146return(this->SepAngle(gamma));
147}
Note: See TracBrowser for help on using the repository browser.