NstProperties.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Nestopia - NES/Famicom emulator written in C++
  4. //
  5. // Copyright (C) 2003-2008 Martin Freij
  6. //
  7. // This file is part of Nestopia.
  8. //
  9. // Nestopia is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // Nestopia is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with Nestopia; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. //
  23. ////////////////////////////////////////////////////////////////////////////////////////
  24. #ifndef NST_PROPERTIES_H
  25. #define NST_PROPERTIES_H
  26. #ifdef NST_PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29. namespace Nes
  30. {
  31. namespace Core
  32. {
  33. class Properties : public ImplicitBool<Properties>
  34. {
  35. public:
  36. Properties(const Properties&);
  37. ~Properties();
  38. Properties& operator = (const Properties&);
  39. bool operator ! () const;
  40. void Clear();
  41. protected:
  42. struct Container;
  43. static wcstring Find(const Container*,uint);
  44. Container* container;
  45. public:
  46. class ConstProxy;
  47. class Proxy
  48. {
  49. protected:
  50. friend class Properties;
  51. friend class ConstProxy;
  52. Container*& container;
  53. const uint id;
  54. Proxy(Container*& c,uint i)
  55. : container(c), id(i) {}
  56. public:
  57. bool operator == (wcstring) const;
  58. void operator = (wcstring);
  59. wcstring operator * () const;
  60. bool operator != (wcstring s) const
  61. {
  62. return !(*this == s);
  63. }
  64. };
  65. class ConstProxy
  66. {
  67. protected:
  68. friend class Properties;
  69. wcstring const function;
  70. ConstProxy(const Container*,uint);
  71. public:
  72. ConstProxy(Proxy);
  73. bool operator == (wcstring) const;
  74. wcstring operator * () const;
  75. bool operator != (wcstring s) const
  76. {
  77. return !(*this == s);
  78. }
  79. };
  80. Properties()
  81. : container(NULL) {}
  82. Proxy operator [] (uint i)
  83. {
  84. return Proxy( container, i );
  85. }
  86. ConstProxy operator [] (uint i) const
  87. {
  88. return ConstProxy( container, i );
  89. }
  90. };
  91. }
  92. }
  93. #endif