LCOV - code coverage report
Current view: top level - opt/gitlab-ci-multi-runner/builds/00e3338d/0/taskrambler/taskrambler/src/class/interface - i_class.c (source / functions) Hit Total Coverage
Test: taskrambler v0.1.8 Lines: 27 27 100.0 %
Date: 2016-04-13 22:40:30 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * \file
       3                 :            :  *
       4                 :            :  * \author      Georg Hopp
       5                 :            :  *
       6                 :            :  * \copyright
       7                 :            :  * Copyright © 2012  Georg Hopp
       8                 :            :  *
       9                 :            :  * This program is free software: you can redistribute it and/or modify
      10                 :            :  * it under the terms of the GNU General Public License as published by
      11                 :            :  * the Free Software Foundation, either version 3 of the License, or
      12                 :            :  * (at your option) any later version.
      13                 :            :  *
      14                 :            :  * This program is distributed in the hope that it will be useful,
      15                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17                 :            :  * GNU General Public License for more details.
      18                 :            :  *
      19                 :            :  * You should have received a copy of the GNU General Public License
      20                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <stdarg.h>
      24                 :            : #include <stdlib.h>
      25                 :            : #include <assert.h>
      26                 :            : 
      27                 :            : #include "class/class.h"
      28                 :            : #include "class/interface/class.h"
      29                 :            : 
      30                 :            : #include "utils/memory.h"
      31                 :            : 
      32                 :            : 
      33                 :            : const
      34                 :            : struct interface i_Class = {
      35                 :            :         "class",
      36                 :            :         3
      37                 :            : };
      38                 :            : 
      39                 :            : void *
      40                 :         22 : classNewParams(class_ptr class, va_list * params)
      41                 :            : {
      42                 :         22 :         void *  object = memCalloc(1, class->object_size + sizeof(void*));
      43                 :            :         int     ret;
      44                 :            : 
      45                 :         22 :         * (class_ptr *)object = class;
      46                 :         22 :         object += sizeof(void*);
      47                 :            : 
      48                 :         22 :         RETCALL(object, Class, ctor, ret, params);
      49                 :            : 
      50                 :         22 :         if (-1 == ret) {
      51                 :          1 :                 classDelete(&object);
      52                 :            :         }
      53                 :            : 
      54                 :         22 :         return object;
      55                 :            : }
      56                 :            : 
      57                 :            : void *
      58                 :         22 : classNew(class_ptr class, ...)
      59                 :            : {
      60                 :            :         va_list   params;
      61                 :            :         void    * object;
      62                 :            : 
      63                 :         22 :         va_start(params, class);
      64                 :         22 :         object = classNewParams(class, &params);
      65                 :         22 :         va_end(params);
      66                 :            : 
      67                 :         22 :         return object;
      68                 :            : }
      69                 :            : 
      70                 :            : void
      71                 :         31 : classDelete(void ** object)
      72                 :            : {
      73                 :         31 :         if (NULL != *object) {
      74                 :            :                 void * mem;
      75                 :            : 
      76                 :         31 :                 CALL(*object, Class, dtor);
      77                 :            : 
      78                 :         31 :                 mem = *object - sizeof(void*);
      79                 :         31 :                 MEM_FREE(mem);
      80                 :         31 :                 *object = NULL;
      81                 :            :         }
      82                 :         31 : }
      83                 :            : 
      84                 :            : void *
      85                 :          2 : classClone(void * _object)
      86                 :            : {
      87                 :          2 :         class_ptr class  = GET_CLASS(_object);
      88                 :          2 :         void *    object = memCalloc(1, class->object_size + sizeof(void*));
      89                 :            : 
      90                 :          2 :         * (class_ptr *)object = class;
      91                 :          2 :         object += sizeof(void*);
      92                 :            : 
      93                 :            : #undef clone
      94                 :          2 :         CALL(object, Class, clone, _object);
      95                 :            : 
      96                 :          2 :         return object;
      97                 :            : }
      98                 :            : 
      99                 :            : // vim: set ts=4 sw=4:

Generated by: LCOV version 1.11