Home | History | Annotate | Download | only in dae
      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 
      9 #ifndef __DAE_STRING_REF_H__
     10 #define __DAE_STRING_REF_H__
     11 
     12 #include <dae/daeMemorySystem.h>
     13 #include <dae/daeStringTable.h>
     14 
     15 /**
     16   *Defines the @c daeStringRef class.
     17  */
     18 class daeStringRef
     19 {
     20 public:
     21 	/**
     22 	 * Macro that defines new and delete overrides for this class
     23 	 */
     24 	DAE_ALLOC
     25 private:
     26 	daeString _string;
     27 	static daeStringTable &_stringTable();
     28 public:
     29 
     30 	/**
     31 	 * Destructor
     32 	 */
     33 	inline ~daeStringRef() { _string = NULL; }
     34 
     35 	/**
     36 	 * Constructor
     37 	 */
     38 	inline daeStringRef() { _string = NULL; }
     39 
     40 	/**
     41 	 * Constructor that copies from another @c daeStringRef.
     42 	 * @param other Reference to copy from.
     43 	 */
     44 	inline daeStringRef(const daeStringRef& other) {
     45 		_string = other._string; }
     46 
     47 	/**
     48 	 * Constructor that creates from a <tt>const char *.</tt>
     49 	 * @param string External string to create from.
     50 	 */
     51 	DLLSPEC daeStringRef(daeString string);
     52 
     53 	/**
     54 	 * Assignment operator.
     55 	 * @param other The daeStringRef to copy.
     56 	 * @return A reference to this object.
     57 	 */
     58 	inline const daeStringRef& operator= (const daeStringRef& other) {
     59 		_string = other._string;
     60 		return *this;
     61 	}
     62 
     63 	/**
     64 	 * Sets a string from an external <tt>const char *.</tt>
     65 	 * @param string The daeString to copy.
     66 	 * @return A reference to this object.
     67 	 */
     68 	DLLSPEC const daeStringRef& set(daeString string);
     69 
     70 	/**
     71 	 * Assignment operator from an external <tt>const char *.</tt>
     72 	 * @param string The daeString to copy.
     73 	 * @return A reference to this object.
     74 	 */
     75 	DLLSPEC const daeStringRef& operator= (daeString string);
     76 
     77 	/**
     78 	 * Cast operator that returns a <tt>const char *.</tt>
     79 	 */
     80 	inline operator daeString() const { return _string; }
     81 
     82 	/**
     83 	 * Comparison operator, the comparison is done via pointers as both
     84 	 * strings will have same pointer if they are the same address
     85 	 * @param other The daeStringRef to compare
     86 	 * @return True if strings are equal. False otherwise.
     87 	 */
     88 	inline bool operator==(const daeStringRef& other) const{
     89 		//return (other._string == _string); }
     90 		return (!strcmp(other._string, _string)); }
     91 
     92 //Contributed by Nus - Wed, 08 Nov 2006
     93 	/**
     94 	 * Release string table...
     95 	 */
     96 	static void releaseStringTable(void);
     97 //--------------------
     98 };
     99 
    100 typedef daeTArray<daeStringRef> daeStringRefArray;
    101 typedef daeTArray<daeStringRefArray> daeStringRefArrayArray;
    102 
    103 #endif //__DAE_STRING_REF_H__
    104