1*b8a377c6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b8a377c6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b8a377c6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b8a377c6SAndrew Rist  * distributed with this work for additional information
6*b8a377c6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b8a377c6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b8a377c6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b8a377c6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b8a377c6SAndrew Rist  *
11*b8a377c6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b8a377c6SAndrew Rist  *
13*b8a377c6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b8a377c6SAndrew Rist  * software distributed under the License is distributed on an
15*b8a377c6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b8a377c6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b8a377c6SAndrew Rist  * specific language governing permissions and limitations
18*b8a377c6SAndrew Rist  * under the License.
19*b8a377c6SAndrew Rist  *
20*b8a377c6SAndrew Rist  *************************************************************/
21*b8a377c6SAndrew Rist 
22*b8a377c6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_EXTERNALVIEWLOGGER_HXX
25cdf0e10cSrcweir #define INCLUDED_EXTERNALVIEWLOGGER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef INCLUDED_LOGGER_HXX
28cdf0e10cSrcweir #include <odiapi/props/Logger.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <fstream>
32cdf0e10cSrcweir #include <stack>
33cdf0e10cSrcweir #include <map>
34cdf0e10cSrcweir #include <utility>
35cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace util {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir   struct NodeDescription
40cdf0e10cSrcweir   {
41cdf0e10cSrcweir 	typedef boost::shared_ptr<NodeDescription> Pointer_t;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 	NodeDescription(const std::string& parent, const std::string& refersTo, const std::string& value, bool inUse);
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	std::string mParentNodeId;
46cdf0e10cSrcweir 	std::string mRefersToNodeId;
47cdf0e10cSrcweir 	std::string mNodeValue;
48cdf0e10cSrcweir 	bool mInUse;
49cdf0e10cSrcweir   };
50cdf0e10cSrcweir 
51cdf0e10cSrcweir   /** A file logger
52cdf0e10cSrcweir    */
53cdf0e10cSrcweir   class ExternalViewLoggerImpl : public Logger
54cdf0e10cSrcweir   {
55cdf0e10cSrcweir   public:
56cdf0e10cSrcweir     ExternalViewLoggerImpl(const std::string& fileName);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     virtual void beginTree();
59cdf0e10cSrcweir     virtual void endTree();
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     virtual void beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse);
62cdf0e10cSrcweir     virtual void endNode(const std::string& nodeId);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir   private:
65cdf0e10cSrcweir     bool isLeaf(const std::string& nodeId);
66cdf0e10cSrcweir     bool isUnreferencedLeaf(const std::string& nodeId);
67cdf0e10cSrcweir     bool isReferenced(const std::string& nodeId);
68cdf0e10cSrcweir 	bool isReferingToOtherNode(const std::string& nodeId);
69cdf0e10cSrcweir 	bool hasParent(const std::string& nodeId);
70cdf0e10cSrcweir     void dumpTree(const std::string& nodeId);
71cdf0e10cSrcweir 	std::string getValue(const std::string& nodeId);
72cdf0e10cSrcweir 	std::string getNewStyleName();
73cdf0e10cSrcweir 	void dumpNodeContainer(const std::string& fileName);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir   private:
76cdf0e10cSrcweir 	typedef std::map<std::string, NodeDescription::Pointer_t> NodeContainer_t;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	std::string mFileName;
79cdf0e10cSrcweir 	NodeContainer_t mNodeContainer;
80cdf0e10cSrcweir 	std::ofstream mFile;
81cdf0e10cSrcweir 	std::stack<std::string> mParentNodeStack;
82cdf0e10cSrcweir   };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir } // namespace util
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #endif // INCLUDED_LOGGER_HXX
87