OpenWalnut  1.5.0dev
WProjectFileIO.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "../kernel/WProjectFile.h"
30 #include "WLogger.h"
31 #include "WProjectFileIO.h"
32 
34  m_errors(),
35  m_applyOrder( POST_MODULES )
36 {
37  // initialize
38 }
39 
41 {
42  // cleanup!
43 }
44 
46 {
47  // do nothing here. Overwrite this method if your specific parser needs to do some post processing.
48 }
49 
51 {
52  return m_errors.size();
53 }
54 
55 const std::vector< std::string >& WProjectFileIO::getErrors() const
56 {
57  return m_errors;
58 }
59 
61 {
62  return m_warnings.size();
63 }
64 
65 const std::vector< std::string >& WProjectFileIO::getWarnings() const
66 {
67  return m_warnings;
68 }
69 
70 void WProjectFileIO::addError( std::string description )
71 {
72  wlog::error( "Project Loader" ) << description;
73  m_errors.push_back( description );
74 }
75 
76 void WProjectFileIO::addWarning( std::string description )
77 {
78  wlog::warn( "Project Loader" ) << description;
79  m_warnings.push_back( description );
80 }
81 
82 void WProjectFileIO::printProperties( std::ostream& output, std::shared_ptr< WProperties > props, std::string indent, //NOLINT
83  std::string prefix, unsigned int index, std::string indexPrefix )
84 {
85  // lock, unlocked if l looses focus
87 
88  output << indent << "// Property Group: " << props->getName() << std::endl;
89 
90  // iterate of them and print them to output
91  for( WProperties::PropertyConstIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
92  {
93  // information properties do not get written
94  if( ( *iter )->getPurpose() == PV_PURPOSE_INFORMATION )
95  {
96  continue;
97  }
98  if( ( *iter )->getType() != PV_GROUP )
99  {
100  output << indent + " " << "PROPERTY:(" << indexPrefix << index << "," << prefix + ( *iter )->getName() << ")="
101  << ( *iter )->getAsString() << std::endl;
102  }
103  else
104  {
105  // it is a group -> recursively print it
106  if( prefix.empty() )
107  {
108  printProperties( output, ( *iter )->toPropGroup(), indent + " ", ( *iter )->getName() + "/", index, indexPrefix );
109  }
110  else
111  {
112  printProperties( output, ( *iter )->toPropGroup(), indent + " ", prefix + ( *iter )->getName() + "/", index, indexPrefix );
113  }
114  }
115  }
116 
117  output << indent << "// Property Group END: " << props->getName() << std::endl;
118 }
119 
121 {
122  m_project = project;
123 }
124 
126 {
127  return m_project;
128 }
129 
131 {
132  return m_applyOrder;
133 }
134 
136 {
137  m_applyOrder = order;
138 }
139 
std::vector< std::string > m_errors
List of errors if any.
void setProject(WProjectFile *project)
Set the project using this parser.
std::vector< std::string > m_warnings
List of warnings if any.
WProjectFile * m_project
The project using this parser.
ApplyOrder getApplyOrder() const
Return the apply order of this IO.
bool hadWarnings() const
Checks whether there where warnings during load or save.
WProjectFileIO()
Default constructor.
virtual void done()
Called whenever the end of the project file has been reached.
const std::vector< std::string > & getErrors() const
Get error list.
bool hadErrors() const
Checks whether there where errors during load or save.
virtual ~WProjectFileIO()
Destructor.
ApplyOrder
When to apply this parser.
void setApplyOrder(ApplyOrder order)
Set the order of calls to "done".
WProjectFile * getProject() const
The project using this parser.
ApplyOrder m_applyOrder
The order in which the "done" functions are called.
void addError(std::string description)
Add an error.
void addWarning(std::string description)
Add an warning.
void printProperties(std::ostream &output, std::shared_ptr< WProperties > props, std::string indent, std::string prefix, unsigned int index, std::string indexPrefix="")
Recursively prints the properties and nested properties.
const std::vector< std::string > & getWarnings() const
Get warnings list.
Class loading project files.
Definition: WProjectFile.h:50
WPropertyGroupBase::PropertyConstIterator PropertyConstIterator
The const iterator type of the container.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298