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 #ifndef INCLUDED_EXTERNALVIEWLOGGER_HXX 25 #define INCLUDED_EXTERNALVIEWLOGGER_HXX 26 27 #ifndef INCLUDED_LOGGER_HXX 28 #include <odiapi/props/Logger.hxx> 29 #endif 30 31 #include <fstream> 32 #include <stack> 33 #include <map> 34 #include <utility> 35 #include <boost/shared_ptr.hpp> 36 37 namespace util { 38 39 struct NodeDescription 40 { 41 typedef boost::shared_ptr<NodeDescription> Pointer_t; 42 43 NodeDescription(const std::string& parent, const std::string& refersTo, const std::string& value, bool inUse); 44 45 std::string mParentNodeId; 46 std::string mRefersToNodeId; 47 std::string mNodeValue; 48 bool mInUse; 49 }; 50 51 /** A file logger 52 */ 53 class ExternalViewLoggerImpl : public Logger 54 { 55 public: 56 ExternalViewLoggerImpl(const std::string& fileName); 57 58 virtual void beginTree(); 59 virtual void endTree(); 60 61 virtual void beginNode(const std::string& nodeId, const std::string& value, const std::string& refersToNodeId, bool inUse); 62 virtual void endNode(const std::string& nodeId); 63 64 private: 65 bool isLeaf(const std::string& nodeId); 66 bool isUnreferencedLeaf(const std::string& nodeId); 67 bool isReferenced(const std::string& nodeId); 68 bool isReferingToOtherNode(const std::string& nodeId); 69 bool hasParent(const std::string& nodeId); 70 void dumpTree(const std::string& nodeId); 71 std::string getValue(const std::string& nodeId); 72 std::string getNewStyleName(); 73 void dumpNodeContainer(const std::string& fileName); 74 75 private: 76 typedef std::map<std::string, NodeDescription::Pointer_t> NodeContainer_t; 77 78 std::string mFileName; 79 NodeContainer_t mNodeContainer; 80 std::ofstream mFile; 81 std::stack<std::string> mParentNodeStack; 82 }; 83 84 } // namespace util 85 86 #endif // INCLUDED_LOGGER_HXX 87