c182f25302c02bf7181db44bc75c302f1ca8b0d5
[occt.git] / src / TestTopOpeTools / TestTopOpeTools_Trace.cxx
1 // Created on: 1994-08-01
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TestTopOpeTools_Trace.hxx>
18
19 TestTopOpeTools_Trace::TestTopOpeTools_Trace
20 (const Standard_Integer nbmaxentry,
21  const TCollection_AsciiString& genre) :
22  mygenre(genre),
23  myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
24  myflag(myfirstentry,mynbmaxentry), 
25  myfunc(myfirstentry,mynbmaxentry), 
26  myftyp(myfirstentry,mynbmaxentry),
27  myverbose(Standard_False),
28  myfverbose(myfirstentry,mynbmaxentry)
29 {}
30
31 TestTopOpeTools_Trace::TestTopOpeTools_Trace
32 (const Standard_Integer nbmaxentry) :
33 mygenre("flag"),
34 myfirstentry(1),mynbmaxentry(nbmaxentry),mynbentries(0),
35 myflag(myfirstentry,mynbmaxentry), 
36 myfunc(myfirstentry,mynbmaxentry), 
37 myftyp(myfirstentry,mynbmaxentry),
38 myverbose(Standard_False),
39 myfverbose(myfirstentry,mynbmaxentry)
40 {}
41
42 Standard_Integer TestTopOpeTools_Trace::Add
43 (const t_flag flag,tf_value func)
44 { return Add(flag,(tf_value)func,te_value); }
45
46 Standard_Integer TestTopOpeTools_Trace::SetVerbose
47 (const Standard_Boolean b)
48 { myverbose = b; return 0;}
49
50 Standard_Integer TestTopOpeTools_Trace::SetVerbose
51 (const t_flag flag,const Standard_Boolean b)
52
53   Standard_Integer index = 0;
54   if ( !Exist(flag,index) ) return 1;
55   if (b) cout<<"set "<<mygenre<<" "<<flag<<" verbose"<<endl;
56   else   cout<<"set "<<mygenre<<" "<<flag<<" not verbose"<<endl;
57   myfverbose.SetValue(index,b);
58   return 0;
59 }
60
61 Standard_Integer TestTopOpeTools_Trace::Set
62 (const Standard_Integer mute,const t_flag flag,const t_value value)
63
64   Standard_Integer index = 0;
65   if ( !Exist(flag,index) ) return 1;
66   if (mute==0) {
67     if (value) cout<<"activation de "<<mygenre<<" "<<flag<<endl;
68     else       cout<<"desactivation de "<<mygenre<<" "<<flag<<endl;
69   }
70   (*((tf_value)Getfunc(index)))(value);
71   return 0;
72 }
73
74 Standard_Integer TestTopOpeTools_Trace::Add
75 (const t_flag flag,tf_intarg func)
76 { return Add(flag,(tf_value)func,te_intarg); }
77
78 Standard_Integer TestTopOpeTools_Trace::Add
79 (const t_flag flag,tf_int_intarg func)
80 { return Add(flag,(tf_value)func,te_int_intarg); }
81
82 Standard_Integer TestTopOpeTools_Trace::Set
83 (const Standard_Integer mute,const t_flag flag, const t_value value,
84  Standard_Integer n, const char** a)
85
86   Standard_Integer index = 0;
87   if ( !Exist(flag,index) ) return 1;
88   if      ( Getftyp(index) == te_intarg ) {
89     (*((tf_intarg)Getfunc(index)))(value,n,a);
90     if (mute==0) {
91       cout<<mygenre<<" "<<flag<<" active avec :";
92       cout<<" "<<value;
93       for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
94       cout<<endl;
95     }
96   }
97   else if ( Getftyp(index) == te_int_intarg ) {
98     Standard_Integer err = (*((tf_int_intarg)Getfunc(index)))(value,n,a);
99     if (err) {
100       cout<<"ERREUR activation de "<<mygenre<<" "<<flag<<" "<<value;
101       for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];cout<<endl;
102     }
103     else {
104       if (mute==0) {
105         cout<<mygenre<<" "<<flag<<" active avec :";
106         cout<<" "<<value;
107         for(Standard_Integer i=0;i<n;i++) cout<<" "<<a[i];
108         cout<<endl;
109       }
110     }
111   }
112   else if ( Getftyp(index) == te_value ) {
113     return Set(mute,flag,value);
114   }
115   else {
116     cout<<"TestTopOpeTools_Trace::Set : unknown function type"<<endl;
117     return 1;
118   }
119   return 0;
120 }
121
122 void TestTopOpeTools_Trace::Dump()
123
124   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++) {
125     if (i==myfirstentry) cout<<"Defined "<<mygenre<<"s :";
126     cout<<" "<<Getflag(i);
127     if (i==mynbentries) cout<<endl;
128   }
129 }
130
131 void TestTopOpeTools_Trace::Reset(const t_value value)
132 {
133   for (Standard_Integer i=myfirstentry;i<=mynbentries;i++)
134     if      (Getftyp(i)==te_value)
135       (*((tf_value)Getfunc(i)))(value);
136     else if (Getftyp(i)==te_intarg)
137       (*((tf_intarg)Getfunc(i)))(value,0,NULL);    
138     else if (Getftyp(i)==te_int_intarg)
139       (*((tf_int_intarg)Getfunc(i)))(value,0,NULL);    
140 }
141
142 // ==== Private
143
144 Standard_Boolean TestTopOpeTools_Trace::Exist
145 (const t_flag flag, Standard_Integer& index)
146
147   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
148     if (myflag.Value(i).IsEqual(flag)) { index = i; return Standard_True; }
149   return Standard_False;         
150 }
151
152 Standard_Boolean TestTopOpeTools_Trace::Exist
153 (const tf_value func, Standard_Integer& index)
154
155   for (Standard_Integer i=myfirstentry; i<=mynbentries; i++)
156     if (myfunc.Value(i) == ((long)func)) { index = i; return Standard_True; }
157   return Standard_False;
158 }
159
160 const t_flag TestTopOpeTools_Trace::Getflag(const Standard_Integer index)
161 { return (t_flag)myflag.Value(index); }
162
163 const tf_value TestTopOpeTools_Trace::Getfunc(const Standard_Integer index)
164 { return (tf_value)myfunc.Value(index); }
165
166 const te_ftyp TestTopOpeTools_Trace::Getftyp(const Standard_Integer index)
167 {
168 //JR/Hp :
169   Standard_Integer intenum = myftyp.Value(index);
170   return (te_ftyp) intenum ;
171 //  return (te_ftyp) myftyp.Value(index);
172 }
173
174 Standard_Integer TestTopOpeTools_Trace::Add
175 (const t_flag flag, const tf_value func, const te_ftyp ftyp)
176
177   Standard_Integer index;
178   if ( Exist(flag,index) || ( mynbentries >= mynbmaxentry) ) return 1;
179   mynbentries++;
180   myflag.SetValue(mynbentries,flag);
181   myfunc.SetValue(mynbentries,(long)func);
182   myftyp.SetValue(mynbentries,(Standard_Integer)ftyp);
183   myfverbose.SetValue(mynbentries,Standard_False);
184   return 0;
185 }