named.h 687 B

12345678910111213141516171819202122232425
  1. #ifndef _NAMED_H
  2. #define _NAMED_H
  3. #include <bfc/common.h>
  4. #include <bfc/string/StringW.h>
  5. class NOVTABLE NamedW
  6. {
  7. public:
  8. NamedW(const wchar_t *initial_name=NULL) : name(initial_name) {}
  9. virtual ~NamedW() {} // placeholder to ensure name is destructed properly
  10. const wchar_t *getName() const { return name; }
  11. const wchar_t *getNameSafe(const wchar_t *defval=NULL) const {
  12. const wchar_t *str = name;
  13. return str ? str : (defval ? defval : L"(null)");
  14. }
  15. void setName(const wchar_t *newname) { if (name.isequal(newname)) return; name = newname; onSetName(); }
  16. // override this to catch name settings
  17. virtual void onSetName() {}
  18. private:
  19. StringW name;
  20. };
  21. #endif