servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / base / init.h
index 465bac4..4b40bea 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <list>
 #include <utility>
 
 #include <list>
 #include <utility>
+#include <lib/base/object.h>
 
 class eAutoInit;
 
 
 class eAutoInit;
 
@@ -26,9 +27,9 @@ class eAutoInit
        virtual void closeNow()=0;
 protected:
        int rl;
        virtual void closeNow()=0;
 protected:
        int rl;
-       char *description;
+       const char *description;
 public:
 public:
-       eAutoInit(int rl, char *description): rl(rl), description(description)
+       eAutoInit(int rl, const char *description): rl(rl), description(description)
        {
        }
        virtual ~eAutoInit();
        {
        }
        virtual ~eAutoInit();
@@ -53,7 +54,7 @@ public:
        {
                return t;
        }
        {
                return t;
        }
-       eAutoInitP1(const T2 &arg, int runl, char *description): eAutoInit(runl, description), arg(arg)
+       eAutoInitP1(const T2 &arg, int runl, const char *description): eAutoInit(runl, description), arg(arg)
        {
                eInit::add(rl, this);
        }
        {
                eInit::add(rl, this);
        }
@@ -84,7 +85,7 @@ public:
        {
                return t;
        }
        {
                return t;
        }
-       eAutoInitP0(int runl, char *description): eAutoInit(runl, description)
+       eAutoInitP0(int runl, const char *description): eAutoInit(runl, description)
        {
                eInit::add(rl, this);
        }
        {
                eInit::add(rl, this);
        }
@@ -94,4 +95,35 @@ public:
        }
 };
 
        }
 };
 
+template<class T1> class
+eAutoInitPtr: protected eAutoInit
+{
+       ePtr<T1> t;
+       void initNow()
+       {
+               t = new T1();
+       }
+       void closeNow()
+       {
+               t = 0;
+       }
+public:
+       operator T1*()
+       {
+               return t;
+       }
+       T1 *operator->()
+       {
+               return t;
+       }
+       eAutoInitPtr(int runl, const char *description): eAutoInit(runl, description)
+       {
+               eInit::add(rl, this);
+       }
+       ~eAutoInitPtr()
+       {
+               eInit::remove(rl, this);
+       }
+};
+
 #endif
 #endif