CCCC - C and C++ Code Counter  9999-git
CCCC Development version (post-3.1.4)
cccc_db.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 #include "cccc.h"
20 #include <fstream>
21 
22 #include "cccc_itm.h"
23 #include "cccc_db.h"
24 
29 
30 #define LINE_BUFFER_SIZE 1000
31 
33 
34 extern CCCC_Project *prj;
35 
36 // the file scope variable last_supplier is used to supress repeated
37 // output of the supplier name in the use relationship section where
38 // the current record has the same supplier as the previous one
39 // the indentation makes this reasonably clear
40 static string last_supplier="";
41 
42 // persistence facilities
43 
44 #define SEP '@'
45 
46 // This function provides the ability for the persistence functions
47 // defined below to do a quick peek at the first token on the stream
48 // leaving the get pointer at the start of that token.
49 // This should be static, but on MSVC++ this gives me an unresolved
50 // symbol at link.
51 bool PeekAtNextLinePrefix(ifstream& ifstr, string pfx)
52 {
53  bool retval=false;
54  char prefix_buffer[1024];
55  size_t initial_stream_pos=ifstr.tellg();
56  ifstr.getline(prefix_buffer,1023,SEP);
57  if(pfx==prefix_buffer)
58  {
59  retval=true;
60  }
61  ifstr.seekg(initial_stream_pos);
62  return retval;
63 }
64 
65 // this is a sort of abstract junkyard function (cf Abstract Factory)
66 template <class T> void DisposeOfImportRecord(T *record_ptr, int fromfile_status)
67 {
68  switch(fromfile_status)
69  {
70  case RECORD_ADDED:
71  // the newly created object has been added to the
72  // database
73  // we must not delete it
74  break;
75 
76  case RECORD_TRANSCRIBED:
77  // the database already had an object for this item
78  // the content of the new object was merged in, but the object
79  // itself is no longer required
80  delete record_ptr;
81  break;
82 
83  default:
84  // something went wrong, so we mention it
85  cerr << "Import error " << fromfile_status
86  << " at line " << ifstr_line
87  << " for " << record_ptr->key()
88  << endl;
89  delete record_ptr;
90  }
91 }
92 
93 // when we add a record to, for example, the extent table for a member of
94 // a module, we need to merge the information in the new extent
95 // with what is already known
96 // there are two kinds of merge:
97 // 1. ordinary fields like module_type should either be consistent or
98 // blank for all extents relating to the same module, so where the old
99 // field is blank, we overwrite with the new field
100 // 2. the flags field in CCCC_Member contains a variety of single character
101 // flags giving the visibility, constness, etc. of the member, with '?' being
102 // used to reflect a state of lack of knowledge: in these cases, any other
103 // value can overwrite '?', all other values do not change.
104 
105 void Resolve_Fields(string& field1, string& field2)
106 {
107  if(field1.size()==0)
108  {
109  field1=field2;
110  }
111 }
112 
113 template
114 void
115 DisposeOfImportRecord(CCCC_Module *record_ptr, int fromfile_status);
116 
117 template
118 void
119 DisposeOfImportRecord(CCCC_Member *record_ptr, int fromfile_status);
120 
121 template
122 void
123 DisposeOfImportRecord(CCCC_UseRelationship *record_ptr, int fromfile_status);
124 
125 template
126 void
127 DisposeOfImportRecord(CCCC_Extent *record_ptr, int fromfile_status);
128 
129 
CCCC_Member * current_loading_extent
Definition: cccc_db.cc:27
void DisposeOfImportRecord(T *record_ptr, int fromfile_status)
Definition: cccc_db.cc:66
int ifstr_line
Definition: cccc_db.cc:32
CCCC_Project * prj
Definition: ccccmain.cc:49
CCCC_Project * current_loading_project
Definition: cccc_db.cc:25
void Resolve_Fields(string &field1, string &field2)
Definition: cccc_db.cc:105
static string last_supplier
Definition: cccc_db.cc:40
bool PeekAtNextLinePrefix(ifstream &ifstr, string pfx)
Definition: cccc_db.cc:51
CCCC_UseRelationship * current_loading_userel
Definition: cccc_db.cc:28
CCCC_Module * current_loading_module
Definition: cccc_db.cc:26
#define SEP
Definition: cccc_db.cc:44