Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexWitness.cxx
1
2 // C++ : Dump python
3
4 // Copyright (C) 2009-2024  CEA, EDF
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "HexWitness.hxx"
23 #include "HexDumpStudy.hxx"
24 #include "HexEltBase.hxx"
25 #include "HexDocument.hxx"
26
27 BEGIN_NAMESPACE_HEXA
28
29 // =================================================== Constructeur
30 Witness::Witness ()
31 {
32    mess_state = NoMessage; 
33    dump_study = NULL; 
34    line_open  = false;;
35    nbr_lines  = 0;
36 }
37 // =================================================== operator << (int)
38 Witness& Witness::operator << (int val)
39 {
40    openMessage ();
41
42    char     valeur [20];
43    sprintf (valeur, "%d", val);
44
45    curr_line += valeur;
46    line_open  = true;
47    return *this;
48 }
49 // =================================================== operator << (double)
50 Witness& Witness::operator << (double val)
51 {
52    openMessage ();
53
54    char valeur [20];
55    sprintf (valeur, "%g", val);
56
57    curr_line += valeur;
58    line_open  = true;
59    return *this;
60 }
61 // =================================================== operator << (cpchar)
62 Witness& Witness::operator << (cpchar val)
63 {
64    openMessage ();
65    curr_line += val;
66    line_open  = true;
67    return *this;
68 }
69 // =================================================== operator << (string)
70 Witness& Witness::operator << (rcstring val)
71 {
72    openMessage ();
73    if (val==Begin)
74        pushLine ();
75
76    curr_line += val;
77    line_open  = true;
78    return *this;
79 }
80 // =================================================== operator << (elt)
81 Witness& Witness::operator << (EltBase* elt)
82 {
83    openMessage ();
84    cpchar name = elt==NULL ? "<null>" : elt->getName();
85    curr_line += name;
86    return *this;
87 }
88 // =================================================== printMessage
89 void Witness::printMessage ()
90 {
91    if (mess_state==NoMessage)
92        return;
93
94    if (line_open) 
95        pushLine ();
96
97    int nbre = bla_bla.size();
98    if (nbre ==0)
99        return;
100
101    std::cout << std::endl 
102         << " ... In function :" << std::endl;
103    std::cout << bla_bla [0] << std::endl << std::endl;
104    for (int nro=1 ; nro<nbre ; nro++)
105        std::cout << bla_bla [nro] << std::endl;
106    std::cout << std::endl;
107 }
108 // =================================================== getMessage
109 TabText& Witness::getMessage ()
110 {
111    if (line_open) 
112        pushLine ();
113
114    return bla_bla;
115 }
116 // =================================================== sizeofMessage
117 int Witness::sizeofMessage ()
118 {
119    if (line_open) 
120        pushLine ();
121
122    return bla_bla.size();
123 }
124 // =================================================== getLine
125 cpchar Witness::getLine (int nro)
126 {
127    if (line_open) 
128        pushLine ();
129
130    if (nro < 0 || nro >= nbr_lines)
131       return "";
132
133    return bla_bla[nro].c_str();
134 }
135
136 // -------------------------------------------------------------
137 // ------------ Private
138 // ------------ For members only
139 // -------------------------------------------------------------
140 // =================================================== openMessage 
141 void Witness::openMessage  ()
142 {
143    if (mess_state!=NoMessage)
144        return;
145
146    mess_state = MessOpen;
147    bla_bla.clear ();
148    if (dump_study == NULL)
149       {
150       curr_line  = "";
151       return;
152       }
153
154    nbr_lines = 0;
155    dump_study->getBegin (curr_line);
156    curr_line += " :" ;
157 }
158 // =================================================== pushLine  
159 void Witness::pushLine  ()
160 {
161    if (mess_state != MessOpen)
162       {
163       nbr_lines = 0;
164       return;
165       }
166
167    bla_bla.push_back (curr_line);
168    curr_line = "";
169    line_open = false;
170    nbr_lines = bla_bla.size ();
171 }
172 END_NAMESPACE_HEXA