Advertisement
Tyler_Elric

SmartThings.hpp

Dec 20th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #pragma once
  2. #include <stdexcept>
  3.  
  4. class Iterable{
  5. public:
  6.     Iterable();
  7.     class Slice{
  8.     private:
  9.         signed long int mStart,mEnd;
  10.     public:
  11.         Slice(signed long int aStart,signed long int aEnd);
  12.         Slice(const Slice& );
  13.         unsigned int start(unsigned int) const throw(std::range_error);
  14.         unsigned int end(unsigned int) const throw(std::range_error);
  15.     };
  16.     class UnneededAllocation{
  17.     private:
  18.         unsigned int mNumRemaining;
  19.     public:
  20.         UnneededAllocation(unsigned int) throw(UnneededAllocation);
  21.         unsigned int remaining();
  22.     };
  23. protected:
  24.     unsigned int mAlloc,mUsed;
  25.     static unsigned int gBufferSize;
  26.     virtual void Allocate(unsigned int) throw(UnneededAllocation) = 0;
  27.     virtual unsigned int newSize(unsigned int) throw(UnneededAllocation);
  28. };
  29.  
  30. class SmartArray:public Iterable
  31. {
  32. protected:
  33.     void Allocate(unsigned int) throw(Iterable::UnneededAllocation);
  34. public:
  35.     class SmartObject{
  36.     protected:
  37.         virtual void destroy() = 0;
  38.         unsigned int mRefCount;
  39.     private:
  40.         SmartObject* createReference();
  41.     public:
  42.         SmartObject();
  43.         class Reference{
  44.         private:
  45.             SmartObject* referenceTo;
  46.         protected:
  47.             void Log( const char* );
  48.         public:
  49.             Reference( SmartObject* );
  50.             Reference( Reference& );
  51.             Reference( void );
  52.             Reference& operator = ( SmartObject* );
  53.             Reference& operator = ( Reference& );
  54.             ~Reference();
  55.             SmartObject& operator () ();
  56.         };
  57.     };
  58.     class Callback
  59.     {
  60.     public:
  61.         virtual SmartObject& operator ()(SmartObject::Reference&,unsigned int ID) const = 0;
  62.     };
  63.     SmartArray(void);
  64.     SmartArray( const SmartArray& );
  65.     ~SmartArray(void);
  66.     SmartArray& ForEach( const Callback& );
  67.     SmartArray& Append( SmartObject* );
  68.     SmartArray& Append( SmartObject::Reference& );
  69.     SmartArray& Insert( SmartObject*, int );
  70.     SmartArray& Prepend( SmartObject* );
  71.     const SmartArray operator [] ( const Slice& );
  72. private:
  73.     SmartObject::Reference* mItems;
  74. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement