1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "FileLoggerImpl.hxx"
25 #include <iostream>
26 
27 using namespace std;
28 
29 namespace util
30 {
31 
FileLoggerImpl(const string & fileName)32     FileLoggerImpl::FileLoggerImpl(const string& fileName) :
33         file_(fileName.c_str())
34     {
35         if (!file_)
36             throw "Cannot open file";
37     }
38 
beginTree()39     void FileLoggerImpl::beginTree()
40     {
41         file_ << "digraph {" << endl;
42     }
43 
endTree()44     void FileLoggerImpl::endTree()
45     {
46         file_ << "}" << endl;
47     }
48 
beginNode(const std::string & nodeId,const std::string & value,const std::string & refersToNodeId,bool inUse)49     void FileLoggerImpl::beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse)
50     {
51         if (!nodeStack_.empty())
52         {
53 		  if (inUse)
54             file_ << nodeId << " [ label=\"(" << value << ")\", shape=box, color=grey, style=filled ];"<< endl;
55 		  else
56 			file_ << nodeId << " [ label=\"(" << value << ")\" ];"<< endl;
57 
58 		  file_ << nodeStack_.top() << " -> " << nodeId << ";" << endl;
59 
60 		  if (!refersToNodeId.empty())
61 			file_ << nodeId << " -> " << refersToNodeId << " [ color=grey, weight=0 ];" << endl;
62         }
63         else
64 		{
65 			file_ << nodeId << " [ label=\"(" << value << ")\", shape=diamond ];"<< endl;
66 		}
67         nodeStack_.push(nodeId);
68     }
69 
endNode(const std::string & nodeId)70     void FileLoggerImpl::endNode(const std::string& nodeId)
71     {
72         nodeStack_.pop();
73     }
74 
75 } // namespace util
76 
77