1 /*
2 
3     This file is part of the Maude 2 interpreter.
4 
5     Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 //
24 //      Implementation for class ViewDatabase.
25 //
26 
27 //      utility stuff
28 #include "macros.hh"
29 #include "vector.hh"
30 
31 //      forward declarations
32 #include "interface.hh"
33 #include "core.hh"
34 #include "mixfix.hh"
35 
36 //	front end class definitions
37 #include "view.hh"
38 #include "viewDatabase.hh"
39 
~ViewDatabase()40 ViewDatabase::~ViewDatabase()
41 {
42   //
43   //	Cleaning up makes for a slow exit, but it helps catch
44   //	dangling pointers and leaked memory when debugging.
45   //
46   const ViewMap::const_iterator e = viewMap.end();
47   for (ViewMap::const_iterator i = viewMap.begin(); i != e; ++i)
48     delete i->second;
49 }
50 
51 bool
insertView(int name,View * view)52 ViewDatabase::insertView(int name, View* view)
53 {
54   pair<ViewMap::iterator, bool> p = viewMap.insert(ViewMap::value_type(name, view));
55   if (p.second)
56     return false;
57   IssueAdvisory("redefining view " << QUOTE(static_cast<NamedEntity*>(view)) << '.');
58   delete p.first->second;
59   p.first->second = view;
60   return true;
61 }
62 
63 View*
getView(int name) const64 ViewDatabase::getView(int name) const
65 {
66   const ViewMap::const_iterator t = viewMap.find(name);
67   return (t == viewMap.end()) ? 0 : t->second;
68 }
69 
70 bool
deleteView(int name)71 ViewDatabase::deleteView(int name)
72 {
73   const ViewMap::iterator t = viewMap.find(name);
74   if (t == viewMap.end())
75     return false;
76   delete t->second;
77   viewMap.erase(t);
78   return true;
79 }
80 
81 void
showNamedViews() const82 ViewDatabase::showNamedViews() const
83 {
84   FOR_EACH_CONST(i, ViewMap, viewMap)
85     cout << "view " << static_cast<NamedEntity*>(i->second) << '\n';
86 }
87