0024331: CMake scripts improvements
[occt.git] / src / TestTopOpeTools / TestTopOpeTools_Trace.cxx
CommitLineData
b311480e 1// Created on: 1994-08-01
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1994-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <TestTopOpeTools_Trace.hxx>
23
24TestTopOpeTools_Trace::TestTopOpeTools_Trace
25(const Standard_Integer nbmaxentry,
26 const TCollection_AsciiString& genre) :
27 mygenre(genre),
28 myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
29 myflag(myfirstentry,mynbmaxentry),
30 myfunc(myfirstentry,mynbmaxentry),
31 myftyp(myfirstentry,mynbmaxentry),
32 myverbose(Standard_False),
33 myfverbose(myfirstentry,mynbmaxentry)
34{}
35
36TestTopOpeTools_Trace::TestTopOpeTools_Trace
37(const Standard_Integer nbmaxentry) :
38mygenre("flag"),
39myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
40myflag(myfirstentry,mynbmaxentry),
41myfunc(myfirstentry,mynbmaxentry),
42myftyp(myfirstentry,mynbmaxentry),
43myverbose(Standard_False),
44myfverbose(myfirstentry,mynbmaxentry)
45{}
46
47Standard_Integer TestTopOpeTools_Trace::Add
48(const t_flag flag,tf_value func)
49{ return Add(flag,(tf_value)func,te_value); }
50
51Standard_Integer TestTopOpeTools_Trace::SetVerbose
52(const Standard_Boolean b)
53{ myverbose = b; return 0;}
54
55Standard_Integer TestTopOpeTools_Trace::SetVerbose
56(const t_flag flag,const Standard_Boolean b)
57{
ad211ad3 58 Standard_Integer index = 0;
7fd59977 59 if ( !Exist(flag,index) ) return 1;
60 if (b) cout<<"set "<<mygenre<<" "<<flag<<" verbose"<<endl;
61 else cout<<"set "<<mygenre<<" "<<flag<<" not verbose"<<endl;
62 myfverbose.SetValue(index,b);
63 return 0;
64}
65
66Standard_Integer TestTopOpeTools_Trace::Set
67(const Standard_Integer mute,const t_flag flag,const t_value value)
68{
ad211ad3 69 Standard_Integer index = 0;
7fd59977 70 if ( !Exist(flag,index) ) return 1;
71 if (mute==0) {
72 if (value) cout<<"activation de "<<mygenre<<" "<<flag<<endl;
73 else cout<<"desactivation de "<<mygenre<<" "<<flag<<endl;
74 }
75 (*((tf_value)Getfunc(index)))(value);
76 return 0;
77}
78
79Standard_Integer TestTopOpeTools_Trace::Add
80(const t_flag flag,tf_intarg func)
81{ return Add(flag,(tf_value)func,te_intarg); }
82
83Standard_Integer TestTopOpeTools_Trace::Add
84(const t_flag flag,tf_int_intarg func)
85{ return Add(flag,(tf_value)func,te_int_intarg); }
86
87Standard_Integer TestTopOpeTools_Trace::Set
88(const Standard_Integer mute,const t_flag flag, const t_value value,
89 Standard_Integer n, const char** a)
90{
ad211ad3 91 Standard_Integer index = 0;
7fd59977 92 if ( !Exist(flag,index) ) return 1;
93 if ( Getftyp(index) == te_intarg ) {
94 (*((tf_intarg)Getfunc(index)))(value,n,a);
95 if (mute==0) {
96 cout<<mygenre<<" "<<flag<<" active avec :";
97 cout<<" "<<value;
98 for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
99 cout<<endl;
100 }
101 }
102 else if ( Getftyp(index) == te_int_intarg ) {
103 Standard_Integer err = (*((tf_int_intarg)Getfunc(index)))(value,n,a);
104 if (err) {
105 cout<<"ERREUR activation de "<<mygenre<<" "<<flag<<" "<<value;
106 for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];cout<<endl;
107 }
108 else {
109 if (mute==0) {
110 cout<<mygenre<<" "<<flag<<" active avec :";
111 cout<<" "<<value;
112 for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
113 cout<<endl;
114 }
115 }
116 }
117 else if ( Getftyp(index) == te_value ) {
118 return Set(mute,flag,value);
119 }
120 else {
121 cout<<"TestTopOpeTools_Trace::Set : unknown function type"<<endl;
122 return 1;
123 }
124 return 0;
125}
126
127void TestTopOpeTools_Trace::Dump()
128{
129 for (Standard_Integer i=myfirstentry; i<=mynbentries; i++) {
130 if (i==myfirstentry) cout<<"Defined "<<mygenre<<"s :";
131 cout<<" "<<Getflag(i);
132 if (i==mynbentries) cout<<endl;
133 }
134}
135
136void TestTopOpeTools_Trace::Reset(const t_value value)
137{
138 for (Standard_Integer i=myfirstentry;i<=mynbentries;i++)
139 if (Getftyp(i)==te_value)
140 (*((tf_value)Getfunc(i)))(value);
141 else if (Getftyp(i)==te_intarg)
142 (*((tf_intarg)Getfunc(i)))(value,0,NULL);
143 else if (Getftyp(i)==te_int_intarg)
144 (*((tf_int_intarg)Getfunc(i)))(value,0,NULL);
145}
146
147// ==== Private
148
149Standard_Boolean TestTopOpeTools_Trace::Exist
150(const t_flag flag, Standard_Integer& index)
151{
152 for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
153 if (myflag.Value(i).IsEqual(flag)) { index = i; return Standard_True; }
154 return Standard_False;
155}
156
157Standard_Boolean TestTopOpeTools_Trace::Exist
158(const tf_value func, Standard_Integer& index)
159{
160 for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
161 if (myfunc.Value(i) == ((long)func)) { index = i; return Standard_True; }
162 return Standard_False;
163}
164
165const t_flag TestTopOpeTools_Trace::Getflag(const Standard_Integer index)
166{ return (t_flag)myflag.Value(index); }
167
168const tf_value TestTopOpeTools_Trace::Getfunc(const Standard_Integer index)
169{ return (tf_value)myfunc.Value(index); }
170
171const te_ftyp TestTopOpeTools_Trace::Getftyp(const Standard_Integer index)
172{
173//JR/Hp :
174 Standard_Integer intenum = myftyp.Value(index);
175 return (te_ftyp) intenum ;
176// return (te_ftyp) myftyp.Value(index);
177}
178
179Standard_Integer TestTopOpeTools_Trace::Add
180(const t_flag flag, const tf_value func, const te_ftyp ftyp)
181{
182 Standard_Integer index;
183 if ( Exist(flag,index) || ( mynbentries >= mynbmaxentry) ) return 1;
184 mynbentries++;
185 myflag.SetValue(mynbentries,flag);
186 myfunc.SetValue(mynbentries,(long)func);
187 myftyp.SetValue(mynbentries,(Standard_Integer)ftyp);
188 myfverbose.SetValue(mynbentries,Standard_False);
189 return 0;
190}