~ubuntu-branches/ubuntu/raring/cccc/raring

« back to all changes in this revision

Viewing changes to .pc/no-dependent-base-lookup.patch/cccc/cccc_tbl.cc

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-04-04 01:42:33 UTC
  • Revision ID: package-import@ubuntu.com-20120404014233-ru9n3ry9ec6m5fid
Tags: 1:3.1.4-3
Avoid dependent base class scope lookups, which no longer work in G++
4.7 (closes: #667133).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    CCCC - C and C++ Code Counter
 
3
    Copyright (C) 1994-2005 Tim Littlefair (tim_littlefair@hotmail.com)
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
18
*/
 
19
// cccc_tbl.cc
 
20
#ifndef _CCCC_TBL_BODY
 
21
#define _CCCC_TBL_BODY
 
22
 
 
23
#include "cccc_itm.h"
 
24
#include "cccc_tbl.h"
 
25
#include <cassert>
 
26
 
 
27
#define LINE_BUFFER_SIZE 1000
 
28
 
 
29
 
 
30
template <class T> CCCC_Table<T>::CCCC_Table() 
 
31
: sorted(true)
 
32
{
 
33
  iter_ = map_t::end(); 
 
34
}
 
35
 
 
36
template <class T> CCCC_Table<T>::~CCCC_Table() 
 
37
{
 
38
  // the container should manage the destruction of its own
 
39
  // nodes correctly, we just need to get rid of the 
 
40
  // objects to which we hold pointers.
 
41
  // NB Although CCCC_Table holds pointers, it owns the 
 
42
  // objects they point to and is responsible for their disposal.
 
43
  T* itemptr=first_item();
 
44
  while(itemptr!=NULL)
 
45
    {
 
46
      delete itemptr;
 
47
      itemptr=next_item();
 
48
    }
 
49
}
 
50
 
 
51
template<class T> 
 
52
int CCCC_Table<T>::get_count(const char* count_tag) 
 
53
{
 
54
  int retval=0;
 
55
  T* itemptr=first_item();
 
56
  while(itemptr!=NULL)
 
57
    {
 
58
      retval+=itemptr->get_count(count_tag);
 
59
      itemptr=next_item();
 
60
    }
 
61
  
 
62
  return retval;
 
63
}
 
64
 
 
65
template<class T> 
 
66
T* CCCC_Table<T>::find(string name)
 
67
{
 
68
  T *retval=NULL;
 
69
  typename map_t::iterator value_iterator=map_t::find(name);
 
70
  if(value_iterator!=map_t::end())
 
71
    {
 
72
      retval=(*value_iterator).second;
 
73
    }
 
74
  return retval;
 
75
}
 
76
 
 
77
template<class T> 
 
78
T* CCCC_Table<T>::find_or_insert(T* new_item_ptr)
 
79
{
 
80
  string new_key=new_item_ptr->key();
 
81
  T *retval=find(new_key);
 
82
  if(retval==NULL)
 
83
    {
 
84
      typename map_t::value_type new_pair(new_key,new_item_ptr);
 
85
      map_t::insert(new_pair);
 
86
      sorted=false;
 
87
      retval=new_item_ptr;
 
88
    }
 
89
  return retval;
 
90
}
 
91
 
 
92
template<class T>
 
93
bool CCCC_Table<T>::remove(T* old_item_ptr)
 
94
{
 
95
  bool retval=false; 
 
96
  typename map_t::iterator value_iterator=map_t::find(old_item_ptr->key());
 
97
  if(value_iterator!=map_t::end())
 
98
    {
 
99
      erase(value_iterator);
 
100
      retval=true;
 
101
    }
 
102
  return retval;
 
103
}
 
104
   
 
105
template <class T> void CCCC_Table<T>::sort() 
 
106
{
 
107
  if(sorted==false)
 
108
    {
 
109
      sorted=true;
 
110
    }
 
111
}
 
112
 
 
113
template <class T> void CCCC_Table<T>::reset_iterator()
 
114
{
 
115
  iter_=map_t::begin();
 
116
}
 
117
 
 
118
template <class T> T* CCCC_Table<T>::first_item()
 
119
{
 
120
  reset_iterator();
 
121
  return next_item();
 
122
}
 
123
 
 
124
template <class T> T* CCCC_Table<T>::next_item()
 
125
{
 
126
  T* retval=NULL;
 
127
  if(iter_!=map_t::end())
 
128
    {
 
129
      retval=(*iter_).second;
 
130
      iter_++;
 
131
    }
 
132
  return retval;
 
133
}
 
134
 
 
135
template <class T> int CCCC_Table<T>::records()
 
136
 
137
  return map_t::size(); 
 
138
}
 
139
 
 
140
#endif // _CCCC_TBL_BODY
 
141
 
 
142
 
 
143
 
 
144
 
 
145
 
 
146
 
 
147
 
 
148
 
 
149
 
 
150
 
 
151