Add doc::write/read_frame_tag()

This commit is contained in:
David Capello 2015-02-17 13:18:24 -03:00
parent 51a03f27ab
commit bcf3b47962
3 changed files with 74 additions and 0 deletions

View File

@ -25,6 +25,7 @@ add_library(doc-lib
file/col_file.cpp
file/gpl_file.cpp
frame_tag.cpp
frame_tag_io.cpp
frame_tags.cpp
image.cpp
image_io.cpp

51
src/doc/frame_tag_io.cpp Normal file
View File

@ -0,0 +1,51 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/frame_tag_io.h"
#include "base/serialization.h"
#include "base/unique_ptr.h"
#include "doc/frame_tag.h"
#include "doc/string_io.h"
#include <iostream>
namespace doc {
using namespace base::serialization;
using namespace base::serialization::little_endian;
void write_frame_tag(std::ostream& os, FrameTag* tag)
{
std::string name = tag->name();
write32(os, tag->id());
write32(os, tag->fromFrame());
write32(os, tag->toFrame());
write32(os, tag->color());
write_string(os, tag->name());
}
FrameTag* read_frame_tag(std::istream& is)
{
ObjectId id = read32(is);
frame_t from = read32(is);
frame_t to = read32(is);
color_t color = read32(is);
std::string name = read_string(is);
base::UniquePtr<FrameTag> tag(new FrameTag(from, to));
tag->setColor(color);
tag->setName(name);
tag->setId(id);
return tag.release();
}
}

22
src/doc/frame_tag_io.h Normal file
View File

@ -0,0 +1,22 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_FRAME_TAG_IO_H_INCLUDED
#define DOC_FRAME_TAG_IO_H_INCLUDED
#pragma once
#include <iosfwd>
namespace doc {
class FrameTag;
void write_frame_tag(std::ostream& os, FrameTag* tag);
FrameTag* read_frame_tag(std::istream& is);
} // namespace doc
#endif