CCCC - C and C++ Code Counter  9999-git
CCCC Development version (post-3.1.4)
cccc_ext.cc
Go to the documentation of this file.
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 /*
20  * cccc_ext.cc
21  */
22 
23 #include "cccc_itm.h"
24 #include "cccc_ext.h"
25 #include "cccc_db.h"
26 #include "cccc_utl.h"
27 
28 unsigned int CCCC_Extent::nextkey=0;
29 
31 {
32  v=vINVALID;
33  ut=utINVALID;
34  extkey=++nextkey;
35 }
36 
38 {
39  char v_as_char='!', ut_as_char='!';
40 
41  if(
42  is.Extract(filename) &&
43  is.Extract(linenumber) &&
44  is.Extract(description) &&
45  is.Extract(flags) &&
46  is.Extract(count_buffer) &&
47  is.Extract(v_as_char) &&
48  is.Extract(ut_as_char)
49  )
50  {
51  v=(Visibility) v_as_char;
52  ut=(UseType) ut_as_char;
53  }
54  else
55  {
56  // we can trust the string constructor to give us empty strings,
57  // but we need to initialise these
58  v=vDONTKNOW;
59  ut=utDONTKNOW;
60  }
61  extkey=++nextkey;
62 }
63 
65 {
66  int retval=FALSE;
67 
68  if(
69  item.Insert(filename) &&
70  item.Insert(linenumber) &&
71  item.Insert(description) &&
72  item.Insert(flags) &&
73  item.Insert(count_buffer) &&
74  item.Insert((char) v) &&
75  item.Insert((char) ut)
76  )
77  {
78  retval=TRUE;
79  }
80 
81  return retval;
82 }
83 
85 {
86  int retval=FALSE;
87  char v_as_char, ut_as_char;
88  if(
89  item.Extract(filename) &&
90  item.Extract(linenumber) &&
91  item.Extract(description) &&
92  item.Extract(flags) &&
93  item.Extract(count_buffer) &&
94  item.Extract(v_as_char) &&
95  item.Extract(ut_as_char)
96  )
97  {
98  v = (Visibility) v_as_char;
99  ut = (UseType) ut_as_char;
100  retval=TRUE;
101  }
102 
103  return retval;
104 }
105 
106 
107 string CCCC_Extent::name(int level) const
108 {
109  string rtnbuf;
110 
111  rtnbuf="";
112 
113  switch(level)
114  {
115  case nlFILENAME:
116  rtnbuf=filename;
117  break;
118  case nlLINENUMBER:
119  rtnbuf=linenumber;
120  break;
121  case nlDESCRIPTION:
122  rtnbuf=description;
123  break;
124  case nlSEARCH:
125  case nlRANK:
126  // Extents have no meaningful internal primary key.
127  // We never want two extents to have the same
128  // key, so we use the running number extkey
129  // which is initialized in both constructors.
130  // This should cause extents to sort in order of
131  // their creation, which is fine.
132  char buf[16];
133  sprintf(buf,"%015d",extkey);
134  rtnbuf=buf;
135  break;
136 
137  default:
138  rtnbuf+=filename;
139  rtnbuf+=":";
140  rtnbuf+=linenumber;
141  }
142  return rtnbuf.c_str();
143 }
144 
145 string CCCC_Extent::key() const { return name(nlRANK); }
146 
147 int CCCC_Extent::get_count(const char* count_tag) {
148  int retval=0;
149  char local_count_buffer[100], *count_tag_ptr, *count_value_ptr;
150  strcpy(local_count_buffer,count_buffer.c_str());
151  count_tag_ptr=strtok(local_count_buffer,":");
152  while(count_tag_ptr!=NULL)
153  {
154  count_value_ptr=strtok(NULL," ");
155  if(strcmp(count_tag_ptr, count_tag) ==0)
156  {
157  retval+=atoi(count_value_ptr);
158  }
159  count_tag_ptr=strtok(NULL,":");
160  }
161  return retval;
162 }
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
string description
Definition: cccc_ext.h:40
static unsigned int nextkey
Definition: cccc_ext.h:45
string filename
Definition: cccc_ext.h:38
unsigned int extkey
Definition: cccc_ext.h:46
string key() const
Definition: cccc_ext.cc:145
bool Insert(const string &s)
Definition: cccc_itm.cc:31
string flags
Definition: cccc_ext.h:41
int get_count(const char *count_tag)
Definition: cccc_ext.cc:147
bool Extract(string &s)
Definition: cccc_itm.cc:47
Visibility
Definition: cccc_utl.h:52
UseType
Definition: cccc_utl.h:65
int GetFromItem(CCCC_Item &item)
Definition: cccc_ext.cc:84
string linenumber
Definition: cccc_ext.h:39
int AddToItem(CCCC_Item &item)
Definition: cccc_ext.cc:64
Visibility v
Definition: cccc_ext.h:44
string count_buffer
Definition: cccc_ext.h:42
UseType ut
Definition: cccc_ext.h:43
string name(int index) const
Definition: cccc_ext.cc:107