spriteforge/include/sfa.hpp

18 lines
701 B
C++
Raw Normal View History

#pragma once
#include "sfa.h"
#include <stdexcept>
#include <string>
namespace spriteforge {
class File {
sfa_owned owned_{};
public:
explicit File(const std::string& path) { if (sfa_load_file(path.c_str(), &owned_) != SFA_OK) throw std::runtime_error("failed to load SFA: "+path); }
~File() { sfa_free_file(&owned_); }
File(const File&) = delete; File& operator=(const File&) = delete;
File(File&& other) noexcept : owned_(other.owned_) { other.owned_={}; }
const sfa_view& view() const noexcept { return owned_.view; }
sfa_frame frame(uint32_t i) const { sfa_frame f{}; if(sfa_get_frame(&owned_.view,i,&f)!=SFA_OK) throw std::out_of_range("SFA frame"); return f; }
};
}