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

Поисковые слова: sojourner
Stellarium: core/renderer/StelRendererStatistics.hpp Source File
Stellarium 0.12.3
StelRendererStatistics.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2012 Ferdinand Majerech
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELRENDERERSTATISTICS_HPP_
21 #define _STELRENDERERSTATISTICS_HPP_
22 
23 
26 enum StatisticSwapMode
27 {
28  StatisticSwapMode_SetToZero,
29  StatisticSwapMode_DoNothing
30 };
31 
59 {
60 friend class StelQGLRenderer;
61 public:
64  : iterationIndex(0)
65  , statisticCount(0)
66  {
67  memset(statistics, '\0', MAX_STATISTICS * sizeof(double));
68  memset(previousStatistics, '\0', MAX_STATISTICS * sizeof(double));
69  memset(statisticNames, '\0', MAX_STATISTICS * sizeof(const char*));
70  memset(swapModes, '\0', MAX_STATISTICS * sizeof(StatisticSwapMode));
71  }
72 
80  bool getNext(const char*& name, double& value)
81  {
82  Q_ASSERT_X(iterationIndex <= statisticCount, Q_FUNC_INFO,
83  "Statistics iteration index out of bounds");
84  if(iterationIndex == statisticCount)
85  {
86  return false;
87  }
88 
89  name = statisticNames[iterationIndex];
90  value = previousStatistics[iterationIndex];
91  ++iterationIndex;
92 
93  return true;
94  }
95 
98  {
99  iterationIndex = 0;
100  }
101 
107  double& operator [] (int index)
108  {
109  Q_ASSERT_X(index >= 0 && index < statisticCount, Q_FUNC_INFO,
110  "Index of a statistic out of range");
111  return statistics[index];
112  }
113 
125  int addStatistic
126  (const char* name, const StatisticSwapMode swapMode = StatisticSwapMode_DoNothing)
127  {
128  Q_ASSERT_X(statisticCount < MAX_STATISTICS, Q_FUNC_INFO,
129  "Can't add any more statistics (at most 48 are supported)");
130  swapModes[statisticCount] = swapMode;
131  statisticNames[statisticCount] = name;
132  ++statisticCount;
133  return statisticCount - 1;
134  }
135 
140  void swap()
141  {
142  memcpy(previousStatistics, statistics, MAX_STATISTICS * sizeof(double));
143  for(int s = 0; s < statisticCount; ++s)
144  {
145  if(swapModes[s] == StatisticSwapMode_SetToZero)
146  {
147  statistics[s] = 0.0f;
148  }
149  else if(swapModes[s] != StatisticSwapMode_DoNothing)
150  {
151  Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown statistic swap mode");
152  }
153  }
154  }
155 
156 private:
158  int iterationIndex;
159 
165  static const int MAX_STATISTICS = 40;
166 
171  double statistics[MAX_STATISTICS];
172 
176  double previousStatistics[MAX_STATISTICS];
177 
185  const char* statisticNames[MAX_STATISTICS];
186 
188  StatisticSwapMode swapModes[MAX_STATISTICS];
189 
191  int statisticCount;
192 };
193 
194 #endif // _STELRENDERERSTATISTICS_HPP_