daeStringRef.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
  5. * file except in compliance with the License. You may obtain a copy of the License at:
  6. * http://research.scea.com/scea_shared_source_license.html
  7. *
  8. * Unless required by applicable law or agreed to in writing, software distributed under the License
  9. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied. See the License for the specific language governing permissions and limitations under the
  11. * License.
  12. */
  13. #ifndef __DAE_STRING_REF_H__
  14. #define __DAE_STRING_REF_H__
  15. #include <dae/daeMemorySystem.h>
  16. #include <dae/daeStringTable.h>
  17. /**
  18. *Defines the @c daeStringRef class.
  19. */
  20. class daeStringRef
  21. {
  22. public:
  23. /**
  24. * Macro that defines new and delete overrides for this class
  25. */
  26. DAE_ALLOC
  27. private:
  28. daeString _string;
  29. static daeStringTable &_stringTable();
  30. public:
  31. /**
  32. * Destructor
  33. */
  34. inline ~daeStringRef() { _string = NULL; }
  35. /**
  36. * Constructor
  37. */
  38. inline daeStringRef() { _string = NULL; }
  39. /**
  40. * Constructor that copies from another @c daeStringRef.
  41. * @param other Reference to copy from.
  42. */
  43. inline daeStringRef(const daeStringRef& other) {
  44. _string = other._string; }
  45. /**
  46. * Constructor that creates from a <tt>const char *.</tt>
  47. * @param string External string to create from.
  48. */
  49. DLLSPEC daeStringRef(daeString string);
  50. /**
  51. * Assignment operator.
  52. * @param other The daeStringRef to copy.
  53. * @return A reference to this object.
  54. */
  55. inline const daeStringRef& operator= (const daeStringRef& other) {
  56. _string = other._string;
  57. return *this;
  58. }
  59. /**
  60. * Sets a string from an external <tt>const char *.</tt>
  61. * @param string The daeString to copy.
  62. * @return A reference to this object.
  63. */
  64. DLLSPEC const daeStringRef& set(daeString string);
  65. /**
  66. * Assignment operator from an external <tt>const char *.</tt>
  67. * @param string The daeString to copy.
  68. * @return A reference to this object.
  69. */
  70. DLLSPEC const daeStringRef& operator= (daeString string);
  71. /**
  72. * Cast operator that returns a <tt>const char *.</tt>
  73. */
  74. inline operator daeString() const { return _string; }
  75. /**
  76. * Comparison operator, the comparison is done via pointers as both
  77. * strings will have same pointer if they are the same address
  78. * @param other The daeStringRef to compare
  79. * @return True if strings are equal. False otherwise.
  80. */
  81. inline bool operator==(const daeStringRef& other) const{
  82. //return (other._string == _string); }
  83. return (!strcmp(other._string, _string)); }
  84. //Contributed by Nus - Wed, 08 Nov 2006
  85. /**
  86. * Release string table...
  87. */
  88. static void releaseStringTable(void);
  89. //--------------------
  90. };
  91. typedef daeTArray<daeStringRef> daeStringRefArray;
  92. typedef daeTArray<daeStringRefArray> daeStringRefArrayArray;
  93. #endif //__DAE_STRING_REF_H__