pandaSystem.cxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. // Filename: pandaSystem.cxx
  2. // Created by: drose (26Jan05)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "pandaSystem.h"
  19. #include "pandaVersion.h"
  20. PandaSystem *PandaSystem::_global_ptr = NULL;
  21. TypeHandle PandaSystem::_type_handle;
  22. ////////////////////////////////////////////////////////////////////
  23. // Function: PandaSystem::Constructor
  24. // Access: Protected
  25. // Description: Don't try to construct a PandaSystem object; there is
  26. // only one of these, and it constructs itself. Use
  27. // get_global_ptr() to get a pointer to the one
  28. // PandaSystem.
  29. ////////////////////////////////////////////////////////////////////
  30. PandaSystem::
  31. PandaSystem() :
  32. _systems(get_class_type())
  33. {
  34. _system_names_dirty = false;
  35. }
  36. ////////////////////////////////////////////////////////////////////
  37. // Function: PandaSystem::Destructor
  38. // Access: Protected
  39. // Description: Don't try to destruct the global PandaSystem object.
  40. ////////////////////////////////////////////////////////////////////
  41. PandaSystem::
  42. ~PandaSystem() {
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. // Function: PandaSystem::get_version_string
  46. // Access: Published, Static
  47. // Description: Returns the current version of Panda, expressed as a
  48. // string, e.g. "1.0.0". The string will end in the
  49. // letter "c" if this build does not represent an
  50. // official version.
  51. ////////////////////////////////////////////////////////////////////
  52. string PandaSystem::
  53. get_version_string() {
  54. return PANDA_VERSION_STR;
  55. }
  56. ////////////////////////////////////////////////////////////////////
  57. // Function: PandaSystem::get_major_version
  58. // Access: Published, Static
  59. // Description: Returns the major version number of the current
  60. // version of Panda. This is the first number of the
  61. // dotted triple returned by get_version_string(). It
  62. // changes very rarely.
  63. ////////////////////////////////////////////////////////////////////
  64. int PandaSystem::
  65. get_major_version() {
  66. return PANDA_MAJOR_VERSION;
  67. }
  68. ////////////////////////////////////////////////////////////////////
  69. // Function: PandaSystem::get_minor_version
  70. // Access: Published, Static
  71. // Description: Returns the minor version number of the current
  72. // version of Panda. This is the second number of the
  73. // dotted triple returned by get_version_string(). It
  74. // changes with each release that introduces new
  75. // features.
  76. ////////////////////////////////////////////////////////////////////
  77. int PandaSystem::
  78. get_minor_version() {
  79. return PANDA_MINOR_VERSION;
  80. }
  81. ////////////////////////////////////////////////////////////////////
  82. // Function: PandaSystem::get_sequence_version
  83. // Access: Published, Static
  84. // Description: Returns the sequence version number of the current
  85. // version of Panda. This is the third number of the
  86. // dotted triple returned by get_version_string(). It
  87. // changes with bugfix updates and very minor feature
  88. // updates.
  89. ////////////////////////////////////////////////////////////////////
  90. int PandaSystem::
  91. get_sequence_version() {
  92. return PANDA_SEQUENCE_VERSION;
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: PandaSystem::is_official_version
  96. // Access: Published, Static
  97. // Description: Returns true if current version of Panda claims to be
  98. // an "official" version, that is, one that was compiled
  99. // by an official distributor of Panda using a specific
  100. // version of the panda source tree. If this is true,
  101. // there will not be a "c" at the end of the version
  102. // string returned by get_version_string().
  103. //
  104. // Note that we must take the distributor's word for it
  105. // here.
  106. ////////////////////////////////////////////////////////////////////
  107. bool PandaSystem::
  108. is_official_version() {
  109. #ifdef PANDA_OFFICIAL_VERSION
  110. return true;
  111. #else
  112. return false;
  113. #endif
  114. }
  115. ////////////////////////////////////////////////////////////////////
  116. // Function: PandaSystem::get_distributor
  117. // Access: Published, Static
  118. // Description: Returns the string defined by the distributor of this
  119. // version of Panda, or "homebuilt" if this version was
  120. // built directly from the sources by the end-user.
  121. // This is a completely arbitrary string.
  122. ////////////////////////////////////////////////////////////////////
  123. string PandaSystem::
  124. get_distributor() {
  125. return PANDA_DISTRIBUTOR;
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. // Function: PandaSystem::get_compiler
  129. // Access: Published, Static
  130. // Description: Returns a string representing the compiler that was
  131. // used to generate this version of Panda, if it is
  132. // available, or "unknown" if it is not.
  133. ////////////////////////////////////////////////////////////////////
  134. string PandaSystem::
  135. get_compiler() {
  136. #if defined(_MSC_VER)
  137. // MSVC defines this macro. It's an integer; we need to format it.
  138. ostringstream strm;
  139. strm << "MSC v." << _MSC_VER;
  140. // We also get this suite of macros that tells us what the build
  141. // platform is.
  142. #if defined(_M_IX86)
  143. #ifdef MS_WIN64
  144. strm << " 64 bit (Intel)";
  145. #else // MS_WIN64
  146. strm << " 32 bit (Intel)";
  147. #endif // MS_WIN64
  148. #elif defined(_M_IA64)
  149. strm << " 64 bit (Itanium)";
  150. #elif defined(_M_AMD64)
  151. strm << " 64 bit (AMD64)";
  152. #endif
  153. return strm.str();
  154. #elif defined(__GNUC__)
  155. // GCC defines this simple macro.
  156. return "GCC " __VERSION__;
  157. #else
  158. // For other compilers, you're on your own.
  159. return "unknown";
  160. #endif
  161. }
  162. ////////////////////////////////////////////////////////////////////
  163. // Function: PandaSystem::get_build_date
  164. // Access: Published, Static
  165. // Description: Returns a string representing the date and time at
  166. // which this version of Panda (or at least dtool) was
  167. // compiled, if available.
  168. ////////////////////////////////////////////////////////////////////
  169. string PandaSystem::
  170. get_build_date() {
  171. return __DATE__ " " __TIME__;
  172. }
  173. ////////////////////////////////////////////////////////////////////
  174. // Function: PandaSystem::has_system
  175. // Access: Published
  176. // Description: Returns true if the current version of Panda claims
  177. // to have the indicated subsystem installed, false
  178. // otherwise. The set of available subsystems is
  179. // implementation defined.
  180. ////////////////////////////////////////////////////////////////////
  181. bool PandaSystem::
  182. has_system(const string &system) const {
  183. Systems::const_iterator si;
  184. si = _systems.find(system);
  185. return (si != _systems.end());
  186. }
  187. ////////////////////////////////////////////////////////////////////
  188. // Function: PandaSystem::get_num_systems
  189. // Access: Published
  190. // Description: Returns the number of Panda subsystems that have
  191. // registered themselves. This can be used with
  192. // get_system() to iterate through the entire list of
  193. // available Panda subsystems.
  194. ////////////////////////////////////////////////////////////////////
  195. int PandaSystem::
  196. get_num_systems() const {
  197. return _systems.size();
  198. }
  199. ////////////////////////////////////////////////////////////////////
  200. // Function: PandaSystem::get_system
  201. // Access: Published
  202. // Description: Returns the nth Panda subsystem that has registered
  203. // itself. This list will be sorted in alphabetical
  204. // order.
  205. ////////////////////////////////////////////////////////////////////
  206. string PandaSystem::
  207. get_system(int n) const {
  208. if (n < 0 || n >= (int)_systems.size()) {
  209. return string();
  210. }
  211. if (_system_names_dirty) {
  212. ((PandaSystem *)this)->reset_system_names();
  213. }
  214. return _system_names[n];
  215. }
  216. ////////////////////////////////////////////////////////////////////
  217. // Function: PandaSystem::get_system_tag
  218. // Access: Published
  219. // Description: Returns the value associated with the indicated tag
  220. // for the given system. This provides a standard way
  221. // to query each subsystem's advertised capabilities.
  222. // The set of tags and values are per-system and
  223. // implementation-defined.
  224. //
  225. // The return value is the empty string if the indicated
  226. // system is undefined or if does not define the
  227. // indicated tag.
  228. ////////////////////////////////////////////////////////////////////
  229. string PandaSystem::
  230. get_system_tag(const string &system, const string &tag) const {
  231. Systems::const_iterator si;
  232. si = _systems.find(system);
  233. if (si != _systems.end()) {
  234. const SystemTags &tags = (*si).second;
  235. SystemTags::const_iterator ti;
  236. ti = tags.find(tag);
  237. if (ti != tags.end()) {
  238. return (*ti).second;
  239. }
  240. }
  241. return string();
  242. }
  243. ////////////////////////////////////////////////////////////////////
  244. // Function: PandaSystem::add_system
  245. // Access: Published
  246. // Description: Intended for use by each subsystem to register itself
  247. // at startup.
  248. ////////////////////////////////////////////////////////////////////
  249. void PandaSystem::
  250. add_system(const string &system) {
  251. bool inserted = _systems.insert(Systems::value_type(system, SystemTags(get_class_type()))).second;
  252. if (inserted) {
  253. _system_names_dirty = true;
  254. }
  255. }
  256. ////////////////////////////////////////////////////////////////////
  257. // Function: PandaSystem::set_system_tag
  258. // Access: Published
  259. // Description: Intended for use by each subsystem to register its
  260. // set of capabilities at startup.
  261. ////////////////////////////////////////////////////////////////////
  262. void PandaSystem::
  263. set_system_tag(const string &system, const string &tag,
  264. const string &value) {
  265. pair<Systems::iterator, bool> result;
  266. result = _systems.insert(Systems::value_type(system, SystemTags(get_class_type())));
  267. if (result.second) {
  268. _system_names_dirty = true;
  269. }
  270. SystemTags &tags = (*result.first).second;
  271. tags[tag] = value;
  272. }
  273. ////////////////////////////////////////////////////////////////////
  274. // Function: PandaSystem::output
  275. // Access: Published
  276. // Description:
  277. ////////////////////////////////////////////////////////////////////
  278. void PandaSystem::
  279. output(ostream &out) const {
  280. out << "Panda version " << get_version_string();
  281. }
  282. ////////////////////////////////////////////////////////////////////
  283. // Function: PandaSystem::write
  284. // Access: Published
  285. // Description:
  286. ////////////////////////////////////////////////////////////////////
  287. void PandaSystem::
  288. write(ostream &out) const {
  289. out << *this << "\n"
  290. << "compiled on " << get_build_date() << " by "
  291. << get_distributor() << "\n"
  292. << "with compiler " << PandaSystem::get_compiler() << "\n\n";
  293. out << "Optional systems:\n";
  294. for (Systems::const_iterator si = _systems.begin();
  295. si != _systems.end();
  296. ++si) {
  297. out << " " << (*si).first << "\n";
  298. const SystemTags &tags = (*si).second;
  299. SystemTags::const_iterator ti;
  300. for (ti = tags.begin(); ti != tags.end(); ++ti) {
  301. out << " " << (*ti).first << " " << (*ti).second << "\n";
  302. }
  303. }
  304. }
  305. ////////////////////////////////////////////////////////////////////
  306. // Function: PandaSystem::get_global_ptr
  307. // Access: Published, Static
  308. // Description: Returns the global PandaSystem object.
  309. ////////////////////////////////////////////////////////////////////
  310. PandaSystem *PandaSystem::
  311. get_global_ptr() {
  312. if (_global_ptr == (PandaSystem *)NULL) {
  313. _global_ptr = new PandaSystem;
  314. }
  315. return _global_ptr;
  316. }
  317. ////////////////////////////////////////////////////////////////////
  318. // Function: PandaSystem::reset_system_names
  319. // Access: Private
  320. // Description: Refills the _system_names vector, which is used for
  321. // get_system_name(), from the current set of available
  322. // system names.
  323. ////////////////////////////////////////////////////////////////////
  324. void PandaSystem::
  325. reset_system_names() {
  326. _system_names.clear();
  327. _system_names.reserve(_systems.size());
  328. Systems::const_iterator si;
  329. for (si = _systems.begin(); si != _systems.end(); ++si) {
  330. _system_names.push_back((*si).first);
  331. }
  332. _system_names_dirty = false;
  333. }