Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. class lisp::RefType
  2. {
  3. public:
  4.   RefType(TypeClass* type) :typeClass(type), refCount(1), weakRefCount(1) {}
  5.    
  6.  
  7.   //type info pointer stored directly.  
  8.   TypeClass* typeClass;   //if it's cloneable etc. It'll actually be part of the typeclass, not the vtable.  typeClass pretty much replaces vtables here.
  9.  
  10.   //other refcounting functions here....
  11.   int refCount, weakRefCount;
  12. protected:
  13.   ~RefType(){}  //deleted only by refcounting - heap object.  note it's non-virtual
  14.   //unassignable, unmoveable.
  15. };
  16.  
  17.  
  18.  
  19. class Array : public lisp::RefType
  20. {
  21.   public:
  22.   Array() : RefType(reflect()) {}
  23.  
  24.   static TypeClass* reflect();
  25.  
  26.   //functions....
  27.  
  28.  
  29.   private:
  30.   Vector<lisp::Expr> data;
  31. };
  32.  
  33. //inside s-expr
  34.  
  35. class Expr
  36. {
  37.  
  38. ...
  39. void setRefType(RefType* refType){...}
  40. RefType* refType(){} //getter
  41.  
  42. template <typename T>
  43. T* refClass()
  44. {
  45.   if (auto out = refType())
  46.   {
  47.     if (T::reflect() == out->typeClass) return static_cast<T*>(out);
  48.   }
  49.   return nullptr;
  50. }
  51.  
  52. {
  53.  
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement