Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wadentry.cpp

Go to the documentation of this file.
00001 // libdoomwad: manipulates Doom wad files.
00002 // Copyright (C) 2005  John Gaughan
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 // This library is distributed with the full text of the LGPL. Please see
00019 // the accompanying file named COPYING.
00020 // 
00021 // You may contact the author at john@johngaughan.net
00022 
00028 // C++ required.
00029 #if !defined __cplusplus
00030 #error C++ compiler required
00031 #endif
00032 
00033 // C++ headers
00034 #include <sstream>
00035 #include <string>
00036 
00037 // Doom headers
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); // null
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 }

Generated on Fri Jun 10 19:38:51 2005 for libdoomwad by  doxygen 1.4.0