daeStringRef.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the MIT Open Source License, for details please see license.txt or the website
  5. * http://www.opensource.org/licenses/mit-license.php
  6. *
  7. */
  8. #ifndef __DAE_STRING_REF_H__
  9. #define __DAE_STRING_REF_H__
  10. #include <dae/daeMemorySystem.h>
  11. #include <dae/daeStringTable.h>
  12. /**
  13. *Defines the @c daeStringRef class.
  14. */
  15. class daeStringRef
  16. {
  17. public:
  18. /**
  19. * Macro that defines new and delete overrides for this class
  20. */
  21. DAE_ALLOC
  22. private:
  23. daeString _string;
  24. static daeStringTable &_stringTable();
  25. public:
  26. /**
  27. * Destructor
  28. */
  29. inline ~daeStringRef() { _string = NULL; }
  30. /**
  31. * Constructor
  32. */
  33. inline daeStringRef() { _string = NULL; }
  34. /**
  35. * Constructor that copies from another @c daeStringRef.
  36. * @param other Reference to copy from.
  37. */
  38. inline daeStringRef(const daeStringRef& other) {
  39. _string = other._string; }
  40. /**
  41. * Constructor that creates from a <tt>const char *.</tt>
  42. * @param string External string to create from.
  43. */
  44. DLLSPEC daeStringRef(daeString string);
  45. /**
  46. * Assignment operator.
  47. * @param other The daeStringRef to copy.
  48. * @return A reference to this object.
  49. */
  50. inline const daeStringRef& operator= (const daeStringRef& other) {
  51. _string = other._string;
  52. return *this;
  53. }
  54. /**
  55. * Sets a string from an external <tt>const char *.</tt>
  56. * @param string The daeString to copy.
  57. * @return A reference to this object.
  58. */
  59. DLLSPEC const daeStringRef& set(daeString string);
  60. /**
  61. * Assignment operator from an external <tt>const char *.</tt>
  62. * @param string The daeString to copy.
  63. * @return A reference to this object.
  64. */
  65. DLLSPEC const daeStringRef& operator= (daeString string);
  66. /**
  67. * Cast operator that returns a <tt>const char *.</tt>
  68. */
  69. inline operator daeString() const { return _string; }
  70. /**
  71. * Comparison operator, the comparison is done via pointers as both
  72. * strings will have same pointer if they are the same address
  73. * @param other The daeStringRef to compare
  74. * @return True if strings are equal. False otherwise.
  75. */
  76. inline bool operator==(const daeStringRef& other) const{
  77. //return (other._string == _string); }
  78. return (!strcmp(other._string, _string)); }
  79. //Contributed by Nus - Wed, 08 Nov 2006
  80. /**
  81. * Release string table...
  82. */
  83. static void releaseStringTable(void);
  84. //--------------------
  85. };
  86. typedef daeTArray<daeStringRef> daeStringRefArray;
  87. typedef daeTArray<daeStringRefArray> daeStringRefArrayArray;
  88. #endif //__DAE_STRING_REF_H__