LCOV - code coverage report
Current view: top level - src - exceptionstack.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 23 38 60.5 %
Date: 2015-01-05 16:01:02 Functions: 8 12 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 36 19.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * exceptionstack.cpp - exception stack class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2004 Stefan Jahn <stefan@lkcc.org>
       5                 :            :  *
       6                 :            :  * This is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2, or (at your option)
       9                 :            :  * any later version.
      10                 :            :  * 
      11                 :            :  * This software is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  * 
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this package; see the file COPYING.  If not, write to
      18                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      19                 :            :  * Boston, MA 02110-1301, USA.  
      20                 :            :  *
      21                 :            :  * $Id$
      22                 :            :  *
      23                 :            :  */
      24                 :            : 
      25                 :            : #if HAVE_CONFIG_H
      26                 :            : # include <config.h>
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include <stdio.h>
      30                 :            : #include <stdlib.h>
      31                 :            : #include <string.h>
      32                 :            : 
      33                 :            : #include "logging.h"
      34                 :            : #include "exception.h"
      35                 :            : #include "exceptionstack.h"
      36                 :            : 
      37                 :            : using namespace qucs;
      38                 :            : 
      39                 :            : // Global exception stack.
      40                 :        107 : exceptionstack qucs::estack;
      41                 :            : 
      42                 :            : // Constructor creates an instance of the exception stack class.
      43                 :        107 : exceptionstack::exceptionstack () {
      44                 :        107 :   root = NULL;
      45                 :        107 : }
      46                 :            : 
      47                 :            : /* This copy constructor creates a instance of the exception stack
      48                 :            :    class based on the given exception stack. */
      49                 :          0 : exceptionstack::exceptionstack (const exceptionstack & e) {
      50                 :          0 :   exception * last, * prev = NULL;
      51 [ #  # ][ #  # ]:          0 :   for (exception * next = e.root; next != NULL; next = next->getNext ()) {
      52 [ #  # ][ #  # ]:          0 :     last = new exception (*next);
      53 [ #  # ][ #  # ]:          0 :     if (prev != NULL)
      54                 :          0 :       prev->setNext (last);
      55                 :            :     else
      56                 :          0 :       root = last;
      57                 :          0 :     prev = last;
      58                 :            :   }
      59                 :          0 : }
      60                 :            : 
      61                 :            : // Destructor deletes an instance of the exception stack class.
      62                 :        107 : exceptionstack::~exceptionstack () {
      63                 :            :   exception * next;
      64 [ -  + ][ #  # ]:        107 :   while (root) {
      65                 :          0 :     next = root->getNext ();
      66 [ #  # ][ #  # ]:          0 :     delete root;
      67                 :          0 :     root = next;
      68                 :            :   }
      69                 :        107 : }
      70                 :            : 
      71                 :            : // The function pushes a new exception onto the exception stack.
      72                 :         82 : void exceptionstack::push (exception * e) {
      73                 :         82 :   e->setNext (root);
      74                 :         82 :   root = e;
      75                 :         82 : }
      76                 :            : 
      77                 :            : /* This function removes the top exception from the exception stack
      78                 :            :    and returns the new top exception. */
      79                 :         82 : exception * exceptionstack::pop (void) {
      80         [ +  - ]:         82 :   if (root != NULL) {
      81                 :         82 :     exception * next = root->getNext ();
      82         [ +  - ]:         82 :     delete root;
      83                 :         82 :     root = next;
      84                 :            :   }
      85                 :         82 :   return root;
      86                 :            : }
      87                 :            : 
      88                 :            : // The function returns the top exception.
      89                 :    1671125 : exception * exceptionstack::top (void) {
      90                 :    1671125 :   return root;
      91                 :            : }
      92                 :            : 
      93                 :            : /* This function prints the complete exception stack and removes each
      94                 :            :    exception from the stack. */
      95                 :        104 : void exceptionstack::print (const char * prefix) {
      96                 :            :   exception * next;
      97         [ -  + ]:        104 :   if (root)
      98                 :            :     logprint (LOG_ERROR, "%s%sexception stack\n",
      99 [ #  # ][ #  # ]:          0 :               prefix ? prefix : "", prefix ? " " : "");
     100         [ -  + ]:        104 :   while ((next = top ()) != NULL) {
     101                 :          0 :     logprint (LOG_ERROR, "  %03d: %s\n", next->getCode (), next->getText ());
     102                 :          0 :     pop ();
     103                 :            :   }
     104 [ +  - ][ +  - ]:        425 : }

Generated by: LCOV version 1.11