Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exceptionstack.cpp
Go to the documentation of this file.
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 exceptionstack qucs::estack;
41 
42 // Constructor creates an instance of the exception stack class.
44  root = NULL;
45 }
46 
47 /* This copy constructor creates a instance of the exception stack
48  class based on the given exception stack. */
50  exception * last, * prev = NULL;
51  for (exception * next = e.root; next != NULL; next = next->getNext ()) {
52  last = new exception (*next);
53  if (prev != NULL)
54  prev->setNext (last);
55  else
56  root = last;
57  prev = last;
58  }
59 }
60 
61 // Destructor deletes an instance of the exception stack class.
63  exception * next;
64  while (root) {
65  next = root->getNext ();
66  delete root;
67  root = next;
68  }
69 }
70 
71 // The function pushes a new exception onto the exception stack.
73  e->setNext (root);
74  root = e;
75 }
76 
77 /* This function removes the top exception from the exception stack
78  and returns the new top exception. */
80  if (root != NULL) {
81  exception * next = root->getNext ();
82  delete root;
83  root = next;
84  }
85  return root;
86 }
87 
88 // The function returns the top exception.
90  return root;
91 }
92 
93 /* This function prints the complete exception stack and removes each
94  exception from the stack. */
95 void exceptionstack::print (const char * prefix) {
96  exception * next;
97  if (root)
98  logprint (LOG_ERROR, "%s%sexception stack\n",
99  prefix ? prefix : "", prefix ? " " : "");
100  while ((next = top ()) != NULL) {
101  logprint (LOG_ERROR, " %03d: %s\n", next->getCode (), next->getText ());
102  pop ();
103  }
104 }
exception top(void)
exceptionstack estack
exception getNext(void)
Definition: exception.h:54
next
Definition: parse_spice.y:859
char * getText(void)
Definition: exception.h:52
void print(const char *prefix=NULL)
void setNext(exception *e)
Definition: exception.h:55
name prefix
Definition: parse_spice.y:131
#define LOG_ERROR
Definition: logging.h:28
void logprint(int level, const char *format,...)
Definition: logging.c:37
exception pop(void)
void push(exception *)
int getCode(void)
Definition: exception.h:50