Документ взят из кэша поисковой машины. Адрес оригинального документа : http://astro.uni-altai.ru/~aw/stellarium/api/gTime_8hpp_source.html
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 07:28:34 2014
Кодировка:

Поисковые слова: р п р п р п р п р п р п р п р п п р п
Stellarium: /home/aw/devel/stellarium/trunk/plugins/Satellites/src/gsatellite/gTime.hpp Source File
Stellarium 0.12.3
gTime.hpp
1 /****************************************************************************
2  * Name: gTime.hpp
3  *
4  * Description: gTime y gTimeSpan classes declaration.
5  * This classes implement the method and operators to manage
6  * calculation over dates and timestamps.
7  *
8  *
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * Copyright (C) 2006 by J. L. Canales *
13  * jlcanales@users.sourceforge.net *
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  * This program is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23  * GNU General Public License for more details. *
24  * *
25  * You should have received a copy of the GNU General Public License *
26  * along with this program; if not, write to the *
27  * Free Software Foundation, Inc., *
28  * 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. *
29  ***************************************************************************/
30 
32 // gTimeSpan and gTime
33 #ifndef _GTIME_HPP_
34 #define _GTIME_HPP_ 1
35 
36 #include <time.h>
37 #include <iostream> // for operator<<(), see below
38 
39 static const double JDAY_JAN1_00H_1900 = 2415019.5; // Jan 1.0 1900 = Jan 1 1900 00h UTC
40 static const double JDAY_JAN1_12H_1900 = 2415020.0; // Jan 1.5 1900 = Jan 1 1900 12h UTC
41 static const double JDAY_JAN1_12H_2000 = 2451545.0; // Jan 1.5 2000 = Jan 1 2000 12h UTC
42 static const double JDAY_JAN1_00H_1970 = 2440587.5;
43 
44 static const double OMEGA_E = 1.002737909350795; // earth rotation per sideral day
45 
46 static const int KSEC_PER_MIN = 60;
47 static const int KSEC_PER_HR = 3600;
48 static const int KSEC_PER_DAY = 86400;
49 static const int KMIN_PER_HR = 60;
50 static const int KMIN_PER_DAY = 1440;
51 static const int KHR_PER_DAY = 60;
52 
53 class gTimeSpan
54 {
55 public:
56  // Constructors
57  gTimeSpan(double timeSpanSrc = 0); // timeSpanSrc is mesured in days and fraction of day
58  gTimeSpan(long lDays, int nHours, int nMins, double nSecs);
59 
60  gTimeSpan(const gTimeSpan& timeSpanSrc);
61  const gTimeSpan& operator=(const gTimeSpan& timeSpanSrc);
62 
63  // Equal to time in Julian Days
64  const gTimeSpan& operator=(const double& timeSpanSrc)
65  {
66  m_timeSpan=timeSpanSrc*KSEC_PER_DAY;
67  return *this;
68  }
69 
70  // Attributes
71  // extract parts
72 
77  long getDays() const;
78 
83  int getHours() const;
84 
89  int getMinutes() const;
90 
95  int getSeconds() const;
96 
102  double getDblSeconds() const;
103 
104 
110  double getDblDays() const;
111  // Operations
112 
114  // TimeSpan Object Math operations
116  gTimeSpan operator-(gTimeSpan timeSpan) const;
117  gTimeSpan operator+(gTimeSpan timeSpan) const;
118  const gTimeSpan& operator+=(gTimeSpan timeSpan);
119  const gTimeSpan& operator-=(gTimeSpan timeSpan);
120  bool operator==(gTimeSpan timeSpan) const;
121  bool operator!=(gTimeSpan timeSpan) const;
122  bool operator<(gTimeSpan timeSpan) const;
123  bool operator>(gTimeSpan timeSpan) const;
124  bool operator<=(gTimeSpan timeSpan) const;
125  bool operator>=(gTimeSpan timeSpan) const;
126 
127 private:
128  double m_timeSpan; //time span in julian days
129 
130 };
131 
132 
133 
134 
135 
141 
142 class gTime
143 {
144 public:
145 
146  // Constructors
147  gTime(double ai_jDays = 0);
148  gTime(int year, double day);
149  gTime(int nYear, int nMonth, int nDay, int nHour, int nMin, double nSec);
150  gTime(struct tm ai_timestruct);
151 
152  // copy constructor
153  gTime(const gTime& timeSrc);
154 
156  // Time Object setting operations
158 
159  // Operation setTime
169  void setTime(int year, double day);
170 
171  // Operation operator=
175  const gTime& operator=(const gTime& timeSrc);
176 
177  // Operation operator=
183  const gTime& operator=(time_t t);
184 
185 
186  // Operation operator=
192  const gTime& operator=(double t)
193  {
194  m_time = t;
195  return *this;
196  }
197 
198 
199 
201  // Time Machine getting operations
203 
204  // Operation getCurrentTime();
209  static gTime getCurrentTime();
210 
211  // Operation getTimeToUTC();
215  static gTimeSpan getTimeToUTC();
216 
217  // Operation: isLeapYear
223  static bool isLeapYear(int ai_year)
224  {
225  return (ai_year % 4 == 0 && ai_year % 100 != 0) || (ai_year % 400 == 0);
226  }
227 
228 
230  // Time Object getting operations
232 
233  // Operation: getGmtTm();
237  double getGmtTm() const;
238 
239  // Operation: getLocalTm();
243  double getLocalTm() const;
244 
245 
247  // Time Object Converting operations
249 
250  // Operation: toTime();
256  time_t toTime() const;
257 
258 
259  void toCalendarDate(int *pYear, int *pMonth , double *pDom) const;
260 
261  double toJCenturies() const;
262 
263  // Operation: toThetaGMST();
276  double toThetaGMST() const;
277 
278  // Operation: toThetaLMST();
285  double toThetaLMST(double longitude) const;
286 
287 
289  // Time Object Math operations
291 
292  gTimeSpan operator-(gTime time) const;
293  gTime operator- (gTimeSpan timeSpan) const;
294  gTime operator+ (gTimeSpan timeSpan) const;
295  const gTime& operator+= (gTimeSpan timeSpan);
296  const gTime& operator-= (gTimeSpan timeSpan);
297  bool operator== (gTime time) const;
298  bool operator!= (gTime time) const;
299  bool operator< (gTime time) const;
300  bool operator> (gTime time) const;
301  bool operator<= (gTime time) const;
302  bool operator>= (gTime time) const;
303 
304 private:
305  double m_time; //Time in Julian Days
306 
307 };
308 
309 
310 
311 inline std::ostream& operator<<(std::ostream& s, gTime& ai_gTime)
312 {
313  int year, month;
314  double Dom;
315 
316  ai_gTime.toCalendarDate(&year, &month , &Dom);
317 
318  s << "GMT " << year <<" " << month <<":"<<Dom;
319  return s;
320 }
321 
322 inline std::ostream& operator<<(std::ostream& s, gTimeSpan& ai_gTimeSpan)
323 {
324  s << "D " <<ai_gTimeSpan.getDays()<<" "<<ai_gTimeSpan.getHours()<<":"<<ai_gTimeSpan.getMinutes()<<":"<<ai_gTimeSpan.getSeconds()<<std::endl;
325  return s;
326 }
327 
328 
329 #endif // _GTIME_HPP_