computedVerticesMakerEntity.I 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Filename: computedVerticesMakerEntity.I
  2. // Created by: drose (02Mar99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, 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://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: ComputedVerticesMakerEntity::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. template<class ValueType, class MorphType>
  24. INLINE ComputedVerticesMakerEntity<ValueType, MorphType>::
  25. ComputedVerticesMakerEntity(const ValueType &value, const MorphType &morphs)
  26. : _value(value), _morphs(morphs) {
  27. }
  28. ////////////////////////////////////////////////////////////////////
  29. // Function: ComputedVerticesMakerEntity::Ordering operator
  30. // Access: Public
  31. // Description:
  32. ////////////////////////////////////////////////////////////////////
  33. template<class ValueType, class MorphType>
  34. bool ComputedVerticesMakerEntity<ValueType, MorphType>::
  35. operator < (const ComputedVerticesMakerEntity<ValueType, MorphType> &other) const {
  36. // First, check the value. This is some vector type, which we
  37. // compare componentwise.
  38. int compare = _value.compare_to(other._value);
  39. if (compare != 0) {
  40. return compare < 0;
  41. }
  42. // The values are identical; compare the morphs.
  43. return _morphs < other._morphs;
  44. }
  45. ////////////////////////////////////////////////////////////////////
  46. // Function: ComputedVerticesMakerEntityMap::add_value
  47. // Access: Public
  48. // Description: Creates a new entry for the value type and morph
  49. // combination, if it is unique, and returns its new
  50. // index number, or returns the index number of a
  51. // previously-created, identical value type and morph.
  52. //
  53. // The PTA table is updated as each new index number is
  54. // allocated so that table[index] == value. It is also
  55. // used to determine the next available index number.
  56. ////////////////////////////////////////////////////////////////////
  57. template<class ValueType, class MorphType>
  58. int ComputedVerticesMakerEntityMap<ValueType, MorphType>::
  59. add_value(const ValueType &value, const MorphType &morphs,
  60. PTA(ValueType) &table) {
  61. // First, see if we have such an entity already.
  62. ComputedVerticesMakerEntity<ValueType, MorphType> entity(value, morphs);
  63. MapType::const_iterator mi = _map.find(entity);
  64. if (mi != _map.end()) {
  65. // We do! Return its index number.
  66. return (*mi).second;
  67. }
  68. // No, this is the first time we've encountered this combination.
  69. // Define it.
  70. int index = table.size();
  71. table.push_back(value);
  72. _map[entity] = index;
  73. return index;
  74. };