1 #include "CppBase.h"
2 #include "Internal.h"
3 
4 namespace Upp {
5 
6 #define LLOG(x)
7 #define LTIMING(x)  DTIMING(x)
8 
Serialize(Stream & s)9 void CppItem::Serialize(Stream& s)
10 {
11 	s % kind % access
12 	  % item % name % natural % at % tparam % param % pname
13 	  % tname % ctname % type % ptype % virt % filetype % file % line % impl
14 	  % using_namespaces;
15 }
16 
17 struct CmpItem {
operator ()Upp::CmpItem18 	bool operator()(const CppItem& a, const String& b) const
19 	{
20 		return a.qitem < b;
21 	}
22 };
23 
FindItem(const Array<CppItem> & x,const String & qitem)24 int FindItem(const Array<CppItem>& x, const String& qitem)
25 {
26 	for(int i = 0; i < x.GetCount(); i++)
27 		if(x[i].qitem == qitem)
28 			return i;
29 	return -1;
30 }
31 
FindNext(const Array<CppItem> & x,int i)32 int FindNext(const Array<CppItem>& x, int i)
33 {
34 	if(i >= x.GetCount())
35 		return i;
36 	String q = x[i].qitem;
37 	while(i < x.GetCount() && x[i].qitem == q)
38 		i++;
39 	return i;
40 }
41 
GetCount(const Array<CppItem> & x,int i)42 int GetCount(const Array<CppItem>& x, int i)
43 {
44 	return FindNext(x, i) - i;
45 }
46 
FindName(const Array<CppItem> & x,const String & name,int i)47 int FindName(const Array<CppItem>& x, const String& name, int i)
48 {
49 	while(i < x.GetCount()) {
50 		if(x[i].name == name)
51 			return i;
52 		i++;
53 	}
54 	return -1;
55 }
56 
IsType(int i) const57 bool CppBase::IsType(int i) const
58 {
59 	return GetKey(i).GetCount();
60 }
61 
Dump(Stream & s)62 void CppBase::Dump(Stream& s)
63 {
64 	for(int i = 0; i < GetCount(); i++) {
65 		s << Nvl(GetKey(i), "<<GLOBALS>>") << "\n";
66 		const Array<CppItem>& m = (*this)[i];
67 		for(int j = 0; j < m.GetCount(); j++)
68 			s << '\t' << m[j] << "\n";
69 	}
70 }
71 
Sweep(const Index<int> & file,bool keep)72 void CppBase::Sweep(const Index<int>& file, bool keep)
73 {
74 	Vector<int> remove;
75 	for(int ni = 0; ni < GetCount(); ni++) {
76 		Array<CppItem>& n = (*this)[ni];
77 		Vector<int> nr;
78 		for(int i = 0; i < n.GetCount(); i++)
79 			if((file.Find(n[i].file) < 0) == keep)
80 				nr.Add(i);
81 		if(nr.GetCount() == n.GetCount())
82 			remove.Add(ni); // remove whole array (later)
83 		else
84 			n.Remove(nr); // only remove some items
85 	}
86 	Remove(remove);
87 }
88 
Append(CppBase && base)89 void CppBase::Append(CppBase&& base)
90 {
91 	for(int i = 0; i < base.GetCount(); i++)
92 		GetAdd(base.GetKey(i)).Append(pick(base[i]));
93 }
94 
RemoveFile(int filei)95 void CppBase::RemoveFile(int filei)
96 {
97 	Index<int> h;
98 	h.Add(filei);
99 	RemoveFiles(h);
100 }
101 
102 
103 }
104