00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028
00029 #if !defined __cplusplus
00030 #error C++ compiler required
00031 #endif
00032
00033
00034 #include <sstream>
00035 #include <string>
00036
00037
00038 #include "global.hpp"
00039 #include "wadentry.hpp"
00040
00041 using namespace Doomwad;
00042
00043 const std::string TextWadEntry::ANIMDEFS = "ANIMDEFS";
00044 const std::string TextWadEntry::CREDITS = "CREDITS";
00045 const std::string TextWadEntry::DECALDEF = "DECALDEF";
00046 const std::string TextWadEntry::DECORATE = "DECORATE";
00047 const std::string TextWadEntry::DEHACKED = "DEHACKED";
00048 const std::string TextWadEntry::DEHSUPP = "DEHSUPP";
00049 const std::string TextWadEntry::KEYCONF = "KEYCONF";
00050 const std::string TextWadEntry::MAPINFO = "MAPINFO";
00051 const std::string TextWadEntry::S_SKIN = "S_SKIN";
00052 const std::string TextWadEntry::SCRIPTS = "SCRIPTS";
00053 const std::string TextWadEntry::SNDINFO = "SNDINFO";
00054 const std::string TextWadEntry::SNDSEQ = "SNDSEQ";
00055 const std::string TextWadEntry::TERRAIN = "TERRAIN";
00056
00062 TextWadEntry::TextWadEntry (const std::string &_name) throw () : name (_name)
00063 {
00064 return;
00065 }
00066
00072 TextWadEntry::TextWadEntry (const Lump &lump) throw ()
00073 {
00074 this->setFromLump (lump);
00075 return;
00076 }
00077
00083 TextWadEntry::~TextWadEntry (void) throw ()
00084 {
00085 return;
00086 }
00087
00098 bool TextWadEntry::setFromLump (const Lump &lump) throw ()
00099 {
00100 std::ostringstream out;
00101 lump.writeToStream (out);
00102 out << '\0';
00103 str = out.str ();
00104 this->setName (lump.getName ());
00105 return true;
00106 }
00107
00116 Lump TextWadEntry::toLump (void) const throw ()
00117 {
00118 Lump lump (this->name);
00119 lump.assign (reinterpret_cast<const byte *> (str.c_str ()), str.size () + 1);
00120 return lump;
00121 }
00122
00130 std::string TextWadEntry::toString (void) const throw ()
00131 {
00132 return str;
00133 }
00134
00144 bool TextWadEntry::setString (const std::string &newStr) throw ()
00145 {
00146 this->str = newStr;
00147 return true;
00148 }
00149
00157 std::string TextWadEntry::getString (void) const throw ()
00158 {
00159 return this->str;
00160 }
00161
00171 bool TextWadEntry::setName (const std::string &newStr) throw ()
00172 {
00173 this->name = newStr;
00174 return true;
00175 }
00176
00184 std::string TextWadEntry::getName (void) const throw ()
00185 {
00186 return this->name;
00187 }
00188
00192 void TextWadEntry::makeDosNewline (void) throw ()
00193 {
00194 std::ostringstream outstr;
00195
00196 this->makeUnixNewline ();
00197
00198 for (std::string::const_iterator i = this->str.begin (); i != this->str.end (); ++i)
00199 {
00200 if (*i == 0x0A) outstr << static_cast<char> (0x0D);
00201 outstr << *i;
00202 }
00203
00204 this->str = outstr.str ();
00205 return;
00206 }
00207
00211 void TextWadEntry::makeMacNewline (void) throw ()
00212 {
00213 std::ostringstream outstr;
00214 char last = 0;
00215
00216 for (std::string::const_iterator i = this->str.begin (); i != this->str.end (); ++i)
00217 {
00218 if (*i == 0x0A && last != 0x0D) outstr << static_cast<char> (0x0D);
00219 else if (*i != 0x0A) outstr << *i;
00220 last = *i;
00221 }
00222
00223 this->str = outstr.str ();
00224 return;
00225 }
00226
00230 void TextWadEntry::makeUnixNewline (void) throw ()
00231 {
00232 std::ostringstream outstr;
00233 char last = 0;
00234
00235 for (std::string::const_iterator i = this->str.begin (); i != this->str.end (); ++i)
00236 {
00237 if (*i == 0x0D) outstr << static_cast<char> (0x0A);
00238 else if (*i == 0x0A && last != 0x0D) outstr << *i;
00239 last = *i;
00240 }
00241
00242 this->str = outstr.str ();
00243 return;
00244 }