gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

pcomponent.cxx (1646B)


      1 /*
      2  *
      3  *  C++ Portable Types Library (PTypes)
      4  *  Version 2.1.1  Released 27-Jun-2007
      5  *
      6  *  Copyright (C) 2001-2007 Hovik Melikyan
      7  *
      8  *  http://www.melikyan.com/ptypes/
      9  *
     10  */
     11 
     12 #include "ptypes.h"
     13 
     14 
     15 namespace ptypes {
     16 
     17 
     18 component::component()
     19     : unknown(), refcount(0), freelist(nil), typeinfo(nil)  {}
     20 
     21 
     22 component::~component() 
     23 {
     24     if (freelist != nil) 
     25     {
     26         for (int i = 0; i < freelist->get_count(); i++)
     27             (*freelist)[i]->freenotify(this);
     28         delete freelist;
     29         freelist = nil;
     30     }
     31 }
     32 
     33 
     34 void component::freenotify(component*) 
     35 {
     36 }
     37 
     38 
     39 void component::addnotification(component* obj) 
     40 {
     41     if (freelist == nil)
     42         freelist = new tobjlist<component>(false);
     43     freelist->add(obj);
     44 }
     45 
     46 
     47 void component::delnotification(component* obj) 
     48 {
     49     int i = -1;
     50     if (freelist != nil) 
     51     {
     52         i = freelist->indexof(obj);
     53         if (i >= 0) {
     54             freelist->del(i);
     55             if (freelist->get_count() == 0) 
     56             {
     57                 delete freelist;
     58                 freelist = nil;
     59             }
     60         }
     61     }
     62     if (i == -1)
     63         fatal(CRIT_FIRST + 1, "delnotification() failed: no such object");
     64 }
     65 
     66 
     67 int component::classid()
     68 {
     69     return CLASS_UNDEFINED;
     70 }
     71 
     72 
     73 component* ptdecl addref(component* c)
     74 {
     75     if (c != nil)
     76 #ifdef PTYPES_ST
     77         c->refcount++;
     78 #else
     79         pincrement(&c->refcount);
     80 #endif
     81     return c;
     82 }
     83 
     84 
     85 bool ptdecl release(component* c)
     86 {
     87     if (c != nil)
     88     {
     89 #ifdef PTYPES_ST
     90         if (--c->refcount == 0)
     91 #else
     92         if (pdecrement(&c->refcount) == 0)
     93 #endif
     94             delete c;
     95         else
     96             return false;
     97     }
     98     return true;
     99 }
    100 
    101 
    102 }