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

ssectors.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 <exception>
00035 #include <sstream>
00036 #include <stdexcept>
00037 #include <string>
00038 
00039 // Doom headers
00040 #include "global.hpp"
00041 #include "lump.hpp"
00042 #include "ssectors.hpp"
00043 #include "wadentry.hpp"
00044 
00045 using namespace Doomwad;
00046 
00047 const size_t Ssector::LENGTH = 0x00000004;
00048 const size_t GLSsector::LENGTH = 0x00000004;
00049 const std::string Ssectors::NAME = "SSECTORS";
00050 const std::string GLSsectors::NAME = "GL_SSECT";
00051 
00060 Ssector::Ssector (uint16 _num, uint16 _first) throw () : numsegs (_num), firstseg (_first)
00061 {
00062 }
00063 
00067 Ssector::~Ssector (void) throw ()
00068 {
00069 }
00070 
00071 size_t Ssector::getLength (void) const throw ()
00072 {
00073   return LENGTH;
00074 }
00075 
00076 bool Ssector::write (Lump &lump, Lump::size_type i) const throw ()
00077 {
00078   try
00079   {
00080     lump.setUInt16 (this->numsegs, i);
00081     lump.setUInt16 (this->firstseg, i + 2);
00082   }
00083   catch (std::range_error &e)
00084   {
00085     return false;
00086   }
00087   return true;
00088 }
00089 
00090 bool Ssector::read (const Lump &lump, Lump::size_type i) throw ()
00091 {
00092   try
00093   {
00094     this->numsegs  = lump.getUInt16 (i);
00095     this->firstseg = lump.getUInt16 (i + 2);
00096   }
00097   catch (std::range_error &e)
00098   {
00099     return false;
00100   }
00101   return true;
00102 }
00103 
00104 std::string Ssector::toString (void) const throw ()
00105 {
00106   std::ostringstream str;
00107 
00108   str << '(' << numsegs << ',' << firstseg << ')';
00109 
00110   return str.str ();
00111 }
00112 
00116 Ssectors::Ssectors (void) throw ()
00117 {
00118   return;
00119 }
00120 
00130 Ssectors::Ssectors (const Lump &lump) throw ()
00131 {
00132   this->setFromLump (lump);
00133   return;
00134 }
00135 
00139 Ssectors::~Ssectors (void) throw ()
00140 {
00141   return;
00142 }
00143 
00144 bool Ssectors::setFromLump (const Lump &lump) throw ()
00145 {
00146   const size_t q = lump.size ();
00147 
00148   if (q % Ssector::LENGTH != 0) return false;
00149 
00150   Ssector s;
00151 
00152   this->clear ();
00153 
00154   for (size_t i = 0; i < q; i += Ssector::LENGTH)
00155   {
00156     s.read (lump, i);
00157     this->push_back (s);
00158   }
00159 
00160   return true;
00161 }
00162 
00163 Lump Ssectors::toLump (void) const throw ()
00164 {
00165   Lump lump (NAME, this->size () * Ssector::LENGTH);
00166   const_iterator iter = this->begin ();
00167   for (size_t i = 0; iter != this->end (); i += Ssector::LENGTH, ++iter)
00168   {
00169     iter->write (lump, i);
00170   }
00171   return lump;
00172 }
00173 
00174 std::string Ssectors::toString (void) const throw ()
00175 {
00176   std::ostringstream str;
00177   for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00178     str << iter->toString () << '\n';
00179   return str.str ();
00180 }
00181 
00185 GLSsector::GLSsector (uint16 num, uint16 first) throw ()
00186 {
00187   // TODO: implement
00188   num = first;
00189   return;
00190 }
00191 
00195 GLSsector::~GLSsector (void) throw ()
00196 {
00197   return;
00198 }
00199 
00200 size_t GLSsector::getLength (void) const throw ()
00201 {
00202   return LENGTH;
00203 }
00204 
00205 bool GLSsector::write (Lump &lump, Lump::size_type i) const throw ()
00206 {
00207   // TODO: implement
00208   i = lump.size ();
00209   return true;
00210 }
00211 
00212 bool GLSsector::read (const Lump &lump, Lump::size_type i) throw ()
00213 {
00214   // TODO: implement
00215   i = lump.size ();
00216   return true;
00217 }
00218 
00219 std::string GLSsector::toString (void) const throw ()
00220 {
00221   // TODO: implement
00222   std::ostringstream str;
00223   return str.str ();
00224 }
00225 
00229 GLSsectors::GLSsectors (void) throw ()
00230 {
00231   return;
00232 }
00233 
00239 GLSsectors::GLSsectors (const Lump &lump) throw ()
00240 {
00241   this->setFromLump (lump);
00242   return;
00243 }
00244 
00248 GLSsectors::~GLSsectors (void) throw ()
00249 {
00250   return;
00251 }
00252 
00253 bool GLSsectors::setFromLump (const Lump &lump) throw ()
00254 {
00255   // TODO: implement
00256   lump.size ();
00257   return true;
00258 }
00259 
00260 Lump GLSsectors::toLump (void) const throw ()
00261 {
00262   // TODO: implement
00263   Lump lump (NAME);
00264   return lump;
00265 }
00266 
00267 std::string GLSsectors::toString (void) const throw ()
00268 {
00269   // TODO: implement
00270   std::ostringstream str;
00271   return str.str ();
00272 }

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