goat3d

annotate src/chunk.cc @ 88:7941e89798e5

selections
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 May 2014 06:52:01 +0300
parents 498ca7ac7047
children
rev   line source
nuclear@54 1 /*
nuclear@54 2 goat3d - 3D scene, character, and animation file format library.
nuclear@54 3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
nuclear@54 4
nuclear@54 5 This program is free software: you can redistribute it and/or modify
nuclear@54 6 it under the terms of the GNU Lesser General Public License as published by
nuclear@54 7 the Free Software Foundation, either version 3 of the License, or
nuclear@54 8 (at your option) any later version.
nuclear@54 9
nuclear@54 10 This program is distributed in the hope that it will be useful,
nuclear@54 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@54 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@54 13 GNU Lesser General Public License for more details.
nuclear@54 14
nuclear@54 15 You should have received a copy of the GNU Lesser General Public License
nuclear@54 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@54 17 */
nuclear@13 18 #include "goat3d.h"
nuclear@13 19 #include "chunk.h"
nuclear@13 20
nuclear@47 21 using namespace g3dimpl;
nuclear@47 22
nuclear@13 23 ChunkHeader chunk_header(int id)
nuclear@13 24 {
nuclear@13 25 ChunkHeader hdr;
nuclear@13 26 hdr.id = id;
nuclear@13 27 hdr.size = sizeof hdr;
nuclear@13 28 return hdr;
nuclear@13 29 }
nuclear@13 30
nuclear@47 31 bool g3dimpl::write_chunk_header(const ChunkHeader *hdr, goat3d_io *io)
nuclear@13 32 {
nuclear@24 33 io->seek(-(long)hdr->size, SEEK_CUR, io->cls);
nuclear@24 34 if(io->write(hdr, sizeof *hdr, io->cls) < (long)sizeof *hdr) {
nuclear@13 35 return false;
nuclear@13 36 }
nuclear@13 37 return true;
nuclear@13 38 }
nuclear@13 39
nuclear@47 40 bool g3dimpl::read_chunk_header(ChunkHeader *hdr, goat3d_io *io)
nuclear@13 41 {
nuclear@24 42 if(io->read(hdr, sizeof *hdr, io->cls) < (long)sizeof *hdr) {
nuclear@13 43 return false;
nuclear@13 44 }
nuclear@13 45 return true;
nuclear@13 46 }
nuclear@13 47
nuclear@47 48 void g3dimpl::skip_chunk(const ChunkHeader *hdr, goat3d_io *io)
nuclear@13 49 {
nuclear@13 50 io->seek(hdr->size - sizeof *hdr, SEEK_CUR, io->cls);
nuclear@13 51 }