Advanced Strategic Command
package.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include "package.h"
22 
23 #include "textfile_evaluation.h"
24 
25 
26 static const int packageStreamVersion = 1;
27 
28 void Package::read ( tnstream& stream )
29 {
30  int v = stream.readInt();
31  if ( v != packageStreamVersion )
32  throw tinvalidversion ( "Package", packageStreamVersion, v );
33 
34  name = stream.readString();
35  description = stream.readString();
36  updateUrl = stream.readString();
37 
38  version.read( stream );
39 
41 
42  archive = stream.readString();
43 }
44 
45 
46 void Package::write ( tnstream& stream ) const
47 {
49  stream.writeString( name );
50  stream.writeString( description );
51  stream.writeString( updateUrl );
52 
53  version.write( stream );
54 
56 
57  stream.writeString ( archive );
58 }
59 
61 {
62  pc.addString( "Name", name );
63  pc.addString( "Description", description );
64  pc.addString( "UpdateURL", updateUrl, "");
65 
66 
68  pc.addString( "Version", s );
69  version.fromString( s );
70 
71  int depCount = dependencies.size();
72  pc.addInteger( "DependencyCount", depCount, 0 );
73 
74  if ( pc.isReading() )
75  dependencies.clear();
76 
77  for ( int i = 0; i < depCount; ++i ) {
78  pc.openBracket( "Dependency" + ASCString::toString(i));
79 
80  while ( pc.isReading() && (dependencies.size() <= i ))
81  dependencies.push_back ( PackageDependency() );
82 
83  pc.addString( "package", dependencies[i].name );
84  ASCString s = dependencies[i].version.toString();
85  pc.addString( "version", s );
86  dependencies[i].version.fromString(s);
87 
88  pc.closeBracket();
89  }
90 
91  archive = pc.getArchive();
92  location = pc.getLocation();
93 }
94 
95 
96 static const int packageDependencyStreamVersion = 1;
97 
99 {
100  int v = stream.readInt();
102  throw tinvalidversion ( "PackageDependency", packageDependencyStreamVersion, v );
103  name = stream.readString();
104  version.read( stream );
105 }
106 
108 {
110  stream.writeString( name );
111  version.write( stream );
112 }
113 
114 
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
virtual ASCString getLocation()=0
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
ASCString updateUrl
Definition: package.h:43
void write(tnstream &stream) const
Definition: package.cpp:107
Functions to evaluate the parsed *.asctxt files.
ASCString description
Definition: package.h:42
The interface for all kinds of IO stream.
void write(tnstream &stream) const
Definition: package.cpp:46
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
static const int packageDependencyStreamVersion
Definition: package.cpp:96
ASCString archive
the archive in which the package is stored
Definition: package.h:52
ASCString toString() const
void read(tnstream &stream)
Definition: package.cpp:98
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
void runTextIO(PropertyContainer &pc)
Definition: package.cpp:60
void read(tnstream &stream)
ASCString location
Definition: package.h:54
void readClassContainer(C &c, tnstream &stream)
Definition: basestrm.h:752
virtual ASCString getArchive()=0
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
void addInteger(const ASCString &name, int &property)
virtual void closeBracket()
VersionIdentifier version
Definition: package.h:45
ASCString name
Definition: package.h:41
void writeClassContainer(const C &c, tnstream &stream)
Definition: basestrm.h:742
virtual void openBracket(const ASCString &name)
void write(tnstream &stream) const
VersionIdentifier version
Definition: package.h:36
static const int packageStreamVersion
Definition: package.cpp:26
void addString(const ASCString &name, ASCString &property)
void fromString(const ASCString &v)
Dependencies dependencies
Definition: package.h:49
void read(tnstream &stream)
Definition: package.cpp:28