From bcf3b4796299a17bbb33bd1c9fc4d16a6f04f7d2 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 17 Feb 2015 13:18:24 -0300 Subject: [PATCH] Add doc::write/read_frame_tag() --- src/doc/CMakeLists.txt | 1 + src/doc/frame_tag_io.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ src/doc/frame_tag_io.h | 22 +++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/doc/frame_tag_io.cpp create mode 100644 src/doc/frame_tag_io.h diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt index e937ad77f..5a27135d9 100644 --- a/src/doc/CMakeLists.txt +++ b/src/doc/CMakeLists.txt @@ -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 diff --git a/src/doc/frame_tag_io.cpp b/src/doc/frame_tag_io.cpp new file mode 100644 index 000000000..cc8b5e990 --- /dev/null +++ b/src/doc/frame_tag_io.cpp @@ -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 + +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 tag(new FrameTag(from, to)); + tag->setColor(color); + tag->setName(name); + tag->setId(id); + return tag.release(); +} + +} diff --git a/src/doc/frame_tag_io.h b/src/doc/frame_tag_io.h new file mode 100644 index 000000000..7db131626 --- /dev/null +++ b/src/doc/frame_tag_io.h @@ -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 + +namespace doc { + + class FrameTag; + + void write_frame_tag(std::ostream& os, FrameTag* tag); + FrameTag* read_frame_tag(std::istream& is); + +} // namespace doc + +#endif