OpenWalnut  1.4.0
WProjectFileIO.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <vector>
00026 #include <string>
00027 
00028 #include "WLogger.h"
00029 
00030 #include "../kernel/WProjectFile.h"
00031 
00032 #include "WProjectFileIO.h"
00033 
00034 WProjectFileIO::WProjectFileIO():
00035     m_errors(),
00036     m_applyOrder( POST_MODULES )
00037 {
00038     // initialize
00039 }
00040 
00041 WProjectFileIO::~WProjectFileIO()
00042 {
00043     // cleanup!
00044 }
00045 
00046 void WProjectFileIO::done()
00047 {
00048     // do nothing here. Overwrite this method if your specific parser needs to do some post processing.
00049 }
00050 
00051 bool WProjectFileIO::hadErrors() const
00052 {
00053     return m_errors.size();
00054 }
00055 
00056 const std::vector< std::string >& WProjectFileIO::getErrors() const
00057 {
00058     return m_errors;
00059 }
00060 
00061 bool WProjectFileIO::hadWarnings() const
00062 {
00063     return m_warnings.size();
00064 }
00065 
00066 const std::vector< std::string >& WProjectFileIO::getWarnings() const
00067 {
00068     return m_warnings;
00069 }
00070 
00071 void WProjectFileIO::addError( std::string description )
00072 {
00073     wlog::error( "Project Loader" ) << description;
00074     m_errors.push_back( description );
00075 }
00076 
00077 void WProjectFileIO::addWarning( std::string description )
00078 {
00079     wlog::warn( "Project Loader" ) << description;
00080     m_warnings.push_back( description );
00081 }
00082 
00083 void WProjectFileIO::printProperties( std::ostream& output, boost::shared_ptr< WProperties > props, std::string indent, //NOLINT
00084                                       std::string prefix, unsigned int index, std::string indexPrefix )
00085 {
00086     // lock, unlocked if l looses focus
00087     WProperties::PropertySharedContainerType::ReadTicket l = props->getProperties();
00088 
00089     output << indent << "// Property Group: " << props->getName() << std::endl;
00090 
00091     // iterate of them and print them to output
00092     for( WProperties::PropertyConstIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
00093     {
00094         // information properties do not get written
00095         if( ( *iter )->getPurpose () == PV_PURPOSE_INFORMATION )
00096         {
00097             continue;
00098         }
00099         if( ( *iter )->getType() != PV_GROUP )
00100         {
00101             output << indent + "    " << "PROPERTY:(" << indexPrefix << index << "," << prefix + ( *iter )->getName() << ")="
00102                    << ( *iter )->getAsString() << std::endl;
00103         }
00104         else
00105         {
00106             // it is a group -> recursively print it
00107             if( prefix.empty() )
00108             {
00109                 printProperties( output, ( *iter )->toPropGroup(), indent + "    ", ( *iter )->getName() + "/", index, indexPrefix );
00110             }
00111             else
00112             {
00113                 printProperties( output, ( *iter )->toPropGroup(), indent + "    ", prefix + ( *iter )->getName() + "/", index, indexPrefix );
00114             }
00115         }
00116     }
00117 
00118     output << indent << "// Property Group END: " << props->getName() << std::endl;
00119 }
00120 
00121 void WProjectFileIO::setProject( WProjectFile* project )
00122 {
00123     m_project = project;
00124 }
00125 
00126 WProjectFile* WProjectFileIO::getProject() const
00127 {
00128     return m_project;
00129 }
00130 
00131 WProjectFileIO::ApplyOrder WProjectFileIO::getApplyOrder() const
00132 {
00133     return m_applyOrder;
00134 }
00135 
00136 void WProjectFileIO::setApplyOrder( WProjectFileIO::ApplyOrder order )
00137 {
00138     m_applyOrder = order;
00139 }
00140