Phoenix
Object-oriented orthogonally persistent operating system
object.h
Go to the documentation of this file.
00001 /*
00002  * /phoenix/include/triton/object.h
00003  *
00004  * This file is a part of Phoenix operating system.
00005  * Copyright (c) 2011-2012, Artyom Lebedev <artyom.lebedev@gmail.com>
00006  * All rights reserved.
00007  * See COPYING file for copyright details.
00008  */
00009 
00014 #ifndef OBJECT_H_
00015 #define OBJECT_H_
00016 
00017 namespace triton {
00018 
00022 class Object {
00023 private:
00024     int _refCount = 0;
00025 public:
00026 
00027     Object() {}
00028 
00029     virtual
00030     ~Object()
00031     {
00032         /* Should be destructed only when last reference released. */
00033         ASSERT(!_refCount);
00034     }
00035 
00037     inline void
00038     AddRef()
00039     {
00040         _refCount++;
00041     }
00042 
00046     inline int
00047     Release()
00048     {
00049         ASSERT(_refCount);
00050         return --_refCount;
00051     }
00052 
00057     virtual const char *
00058     __name__() const
00059     {
00060         return "Object";
00061     }
00062 
00064     typedef u64 hash_t;
00065 
00072     virtual hash_t
00073     __hash__() const
00074     {
00075         /* Default implementation returns constant value. */
00076         return 1;
00077     }
00078 };
00079 
00085 inline Object::hash_t
00086 hash(Object &obj)
00087 {
00088     return obj.__hash__();
00089 }
00090 
00091 inline Object::hash_t
00092 hash(Object &&obj)
00093 {
00094     return obj.__hash__();
00095 }
00096 
00100 class Container: public Object {
00101 public:
00105     virtual size_t
00106     __len__()
00107     {
00108         return 0;
00109     }
00110 };
00111 
00117 inline size_t
00118 len(Container &obj)
00119 {
00120     return obj.__len__();
00121 }
00122 
00128 inline size_t
00129 len(Container &&obj)
00130 {
00131     return obj.__len__();
00132 }
00133 
00137 class Iterable: public Container {
00138     //XXX
00139 };
00140 
00141 } /* namespace triton */
00142 
00143 #endif /* OBJECT_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines