package.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include "package.h"
00022 
00023 #include "textfile_evaluation.h"
00024 
00025 
00026 static const int packageStreamVersion  = 1;
00027 
00028 void Package::read ( tnstream& stream )
00029 {
00030    int v = stream.readInt();
00031    if ( v != packageStreamVersion  )
00032       throw tinvalidversion ( "Package", packageStreamVersion, v );
00033    
00034    name = stream.readString();
00035    description = stream.readString();
00036    updateUrl = stream.readString();
00037       
00038    version.read( stream );
00039       
00040    readClassContainer( dependencies, stream );
00041       
00042    archive = stream.readString();
00043 }
00044 
00045 
00046 void Package::write ( tnstream& stream ) const
00047 {
00048    stream.writeInt( packageStreamVersion );
00049    stream.writeString( name );
00050    stream.writeString( description );
00051    stream.writeString( updateUrl );
00052       
00053    version.write( stream );
00054       
00055    writeClassContainer( dependencies, stream );
00056       
00057    stream.writeString ( archive );
00058 }
00059 
00060 void Package::runTextIO ( PropertyContainer& pc )
00061 {
00062    pc.addString( "Name", name );
00063    pc.addString( "Description", description );
00064    pc.addString( "UpdateURL", updateUrl, "");
00065    
00066    
00067    ASCString s = version.toString();
00068    pc.addString( "Version", s );
00069    version.fromString( s );
00070    
00071    int depCount = dependencies.size();
00072    pc.addInteger( "DependencyCount", depCount, 0 );
00073    
00074    if ( pc.isReading() )
00075       dependencies.clear();
00076    
00077    for ( int i = 0; i < depCount; ++i ) {
00078       pc.openBracket( "Dependency" + ASCString::toString(i));
00079       
00080       while ( pc.isReading() && (dependencies.size() <= i )) 
00081          dependencies.push_back ( PackageDependency() );
00082       
00083       pc.addString( "package", dependencies[i].name );
00084       ASCString s = dependencies[i].version.toString();
00085       pc.addString( "version", s );
00086       dependencies[i].version.fromString(s);
00087       
00088       pc.closeBracket();
00089    }
00090    
00091    archive = pc.getArchive();
00092    location = pc.getLocation();
00093 }
00094 
00095 
00096 static const int packageDependencyStreamVersion  = 1;
00097 
00098 void Package::PackageDependency::read ( tnstream& stream )
00099 {
00100    int v = stream.readInt();
00101    if ( v != packageDependencyStreamVersion  )
00102       throw tinvalidversion ( "PackageDependency", packageDependencyStreamVersion, v );
00103    name = stream.readString();
00104    version.read( stream );
00105 }
00106 
00107 void Package::PackageDependency::write ( tnstream& stream ) const
00108 {
00109    stream.writeInt( packageDependencyStreamVersion );
00110    stream.writeString( name );
00111    version.write( stream );
00112 }
00113 
00114             

Generated on Mon May 21 01:26:35 2012 for Advanced Strategic Command by  doxygen 1.5.1