1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom 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 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef TrenchBroom_MapFileSerializer 21 #define TrenchBroom_MapFileSerializer 22 23 #include "IO/NodeSerializer.h" 24 #include "Model/MapFormat.h" 25 #include "Model/Brush.h" 26 #include "Model/Node.h" 27 28 #include <cstdio> 29 30 namespace TrenchBroom { 31 namespace IO { 32 class Path; 33 34 class MapFileSerializer : public NodeSerializer { 35 private: 36 typedef std::vector<size_t> LineStack; 37 LineStack m_startLineStack; 38 size_t m_line; 39 FILE* m_stream; 40 public: 41 static Ptr create(Model::MapFormat::Type format, FILE* stream); 42 protected: 43 MapFileSerializer(FILE* file); 44 private: 45 void doBeginEntity(const Model::Node* node); 46 void doEndEntity(Model::Node* node); 47 void doEntityAttribute(const Model::EntityAttribute& attribute); 48 void doBeginBrush(const Model::Brush* brush); 49 void doEndBrush(Model::Brush* brush); 50 void doBrushFace(Model::BrushFace* face); 51 private: 52 void setFilePosition(Model::Node* node); 53 size_t startLine(); 54 private: 55 virtual size_t doWriteBrushFace(FILE* stream, Model::BrushFace* face) = 0; 56 }; 57 } 58 } 59 60 #endif /* defined(TrenchBroom_MapFileSerializer) */ 61