From b92b35f191d2d99675dd35561eb06f8352bf8e7d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Fri, 28 May 2021 12:41:21 +0200 Subject: [PATCH] ressources are not reloadable, ressource interface deleted --- lib/Ray/CMakeLists.txt | 1 - lib/Ray/sources/Audio/IAudio.hpp | 10 +- lib/Ray/sources/Audio/Music.cpp | 12 -- lib/Ray/sources/Audio/Music.hpp | 6 - lib/Ray/sources/Audio/Sound.cpp | 12 -- lib/Ray/sources/Audio/Sound.hpp | 6 - lib/Ray/sources/Drawables/Image.cpp | 17 -- lib/Ray/sources/Drawables/Image.hpp | 18 +- lib/Ray/sources/Drawables/Texture.cpp | 51 ++--- lib/Ray/sources/Drawables/Texture.hpp | 22 +-- lib/Ray/sources/Font.cpp | 12 -- lib/Ray/sources/Font.hpp | 11 +- lib/Ray/sources/IRessource.hpp | 25 --- lib/Ray/sources/Model/Model.cpp | 186 ++++++++---------- lib/Ray/sources/Model/Model.hpp | 13 +- .../Renderer/Drawable3DComponent.hpp | 1 + sources/main.cpp | 84 -------- 17 files changed, 123 insertions(+), 364 deletions(-) delete mode 100644 lib/Ray/sources/IRessource.hpp diff --git a/lib/Ray/CMakeLists.txt b/lib/Ray/CMakeLists.txt index 0167d524..17d97db0 100644 --- a/lib/Ray/CMakeLists.txt +++ b/lib/Ray/CMakeLists.txt @@ -14,7 +14,6 @@ endif () set(HEADERS sources/Color.hpp sources/Font.hpp - sources/IRessource.hpp sources/Matrix.hpp sources/Mesh.hpp sources/TraceLog.hpp diff --git a/lib/Ray/sources/Audio/IAudio.hpp b/lib/Ray/sources/Audio/IAudio.hpp index 65753870..a6120f5e 100644 --- a/lib/Ray/sources/Audio/IAudio.hpp +++ b/lib/Ray/sources/Audio/IAudio.hpp @@ -7,23 +7,15 @@ #ifndef AUDIO_HPP_ #define AUDIO_HPP_ - -#include "IRessource.hpp" #include namespace RAY::Audio { //! @brief Interface for Audio ressources - class IAudio: public IRessource { + class IAudio { public: virtual ~IAudio() = default; - //! @brief Load Audio stream from file - virtual bool load(const std::string &path) = 0; - - //! @brief Unload audio stream - virtual bool unload(void) = 0; - //! @brief Check if audio is playing virtual bool isPlaying(void) = 0; diff --git a/lib/Ray/sources/Audio/Music.cpp b/lib/Ray/sources/Audio/Music.cpp index 09e7b540..b397c04e 100644 --- a/lib/Ray/sources/Audio/Music.cpp +++ b/lib/Ray/sources/Audio/Music.cpp @@ -18,20 +18,8 @@ RAY::Audio::Music::Music() } RAY::Audio::Music::~Music() -{ - this->unload(); -} - -bool RAY::Audio::Music::load(const std::string &path) -{ - _music = LoadMusicStream(path.c_str()); - return true; -} - -bool RAY::Audio::Music::unload(void) { UnloadMusicStream(_music); - return true; } bool RAY::Audio::Music::isPlaying(void) diff --git a/lib/Ray/sources/Audio/Music.hpp b/lib/Ray/sources/Audio/Music.hpp index 46942597..85f31c52 100644 --- a/lib/Ray/sources/Audio/Music.hpp +++ b/lib/Ray/sources/Audio/Music.hpp @@ -34,12 +34,6 @@ namespace RAY::Audio //! @brief A Music is assignable Music &operator=(const Music &Music) = default; - //! @brief Load Music stream from file - bool load(const std::string &path) override; - - //! @brief Unload Music stream - bool unload(void) override; - //! @brief Check if Music is playing bool isPlaying(void) override; diff --git a/lib/Ray/sources/Audio/Sound.cpp b/lib/Ray/sources/Audio/Sound.cpp index f647672f..4bfcb95a 100644 --- a/lib/Ray/sources/Audio/Sound.cpp +++ b/lib/Ray/sources/Audio/Sound.cpp @@ -18,20 +18,8 @@ RAY::Audio::Sound::Sound() } RAY::Audio::Sound::~Sound() -{ - this->unload(); -} - -bool RAY::Audio::Sound::load(const std::string &path) -{ - _sound = LoadSound(path.c_str()); - return true; -} - -bool RAY::Audio::Sound::unload(void) { UnloadSound(_sound); - return true; } bool RAY::Audio::Sound::isPlaying(void) diff --git a/lib/Ray/sources/Audio/Sound.hpp b/lib/Ray/sources/Audio/Sound.hpp index 4ceb29d0..32dd8cb0 100644 --- a/lib/Ray/sources/Audio/Sound.hpp +++ b/lib/Ray/sources/Audio/Sound.hpp @@ -34,12 +34,6 @@ namespace RAY::Audio //! @brief A Sound is assignable Sound &operator=(const Sound &sound) = default; - //! @brief Load Sound stream from file - bool load(const std::string &path) override; - - //! @brief Unload Sound stream - bool unload(void) override; - //! @brief Check if Sound is playing bool isPlaying(void) override; diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index b7bbdbc4..0145e642 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -13,11 +13,6 @@ RAY::Image::Image(const std::string &filename): { } -RAY::Image::Image() -{ - -} - RAY::Image::Image(RAY::Texture &texture): _image(GetTextureData(texture)) { @@ -29,24 +24,12 @@ RAY::Image::~Image() UnloadImage(_image); } -bool RAY::Image::load(const std::string &filename) -{ - this->_image = LoadImage(filename.c_str()); - return true; -} - bool RAY::Image::exportTo(const std::string &outputPath) { ExportImage(_image, outputPath.c_str()); return true; } -bool RAY::Image::unload() -{ - UnloadImage(_image); - return true; -} - RAY::Image::operator ::Image() const { return _image; diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index 6819ddd1..ac802580 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -11,16 +11,14 @@ #include #include #include "Texture.hpp" -#include "IRessource.hpp" namespace RAY { namespace Drawables { class ADrawable2D; } - class IRessource; //! @brief Object representation of a framebuffer - class Image: public IRessource { + class Image { public: //! @brief Create an image, loading a file //! @param filename: path to file to load @@ -31,28 +29,18 @@ namespace RAY Image(Texture &texture); //! @brief A default copy constructor - Image(const Image &image) = default; - - //! @brief A default constructor, no ressources loaded - Image(); + Image(const Image &image) = delete; //! @brief An image is assignable - Image &operator=(const Image &image) = default; + Image &operator=(const Image &image) = delete; //! @brief Image destructor, will unload ressources ~Image(); - //! @brief load ressources from file - //! @param filename: path of input - bool load(const std::string &filename) override; - //! @brief export to file //! @param outputPath: path of output bool exportTo(const std::string &outputPath); - //! @brief unload ressources - bool unload() override; - //! @brief draw drawable void draw(Drawables::ADrawable2D &); diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index c70fcf59..a92e1349 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -7,35 +7,36 @@ #include "Drawables/Texture.hpp" -RAY::Texture::Texture(const std::string &filename): - _texture(LoadTexture(filename.c_str())) -{ -} +namespace RAY { -RAY::Texture::Texture(const Image &image): - _texture(LoadTextureFromImage(image)) -{ + Texture::Texture(const std::string &filename): + _texture(LoadTexture(filename.c_str())), + _resourcePath(filename) + { + } -} + Texture::Texture(const Texture &texture): + _texture(LoadTexture(texture._resourcePath.c_str())), + _resourcePath(texture._resourcePath) + { + } -RAY::Texture::~Texture() -{ - UnloadTexture(this->_texture); -} -bool RAY::Texture::load(const std::string &filename) -{ - this->_texture = LoadTexture(filename.c_str()); - return true; -} + Texture &Texture::operator=(const Texture &other) + { + UnloadTexture(this->_texture); + this->_resourcePath = other._resourcePath; + this->_texture = LoadTexture(this->_resourcePath.c_str()); + return *this; + } -bool RAY::Texture::unload() -{ - UnloadTexture(this->_texture); - return true; -} + Texture::~Texture() + { + UnloadTexture(this->_texture); + } -RAY::Texture::operator ::Texture() const -{ - return this->_texture; + Texture::operator ::Texture() const + { + return this->_texture; + } } diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 81b07e0f..a2054b1a 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -10,42 +10,32 @@ #include #include -#include "IRessource.hpp" namespace RAY { //! @brief Object representation of a texture - class Texture: public IRessource { + class Texture { public: //! @brief Create an texture, loading a file //! @param filename: path to file to load Texture(const std::string &filename); - //! @brief Create an texture, from an image - //! @param image: reference to image to create texture from - Texture(const Image &image); - //! @brief A texture is not copy constructable - Texture(const Texture &) = delete; + Texture(const Texture &); //! @brief An image is assignable - Texture &operator=(const Texture &) = delete; + Texture &operator=(const Texture &); //! @brief Texture destructor, will unload ressources - ~Texture() override; - - //! @brief load ressources from file - //! @param filename: path of input - bool load(const std::string &filename) override; - - //! @brief unload ressources - bool unload() override; + ~Texture(); protected: private: //! @brief Texture, really, that's just it... ::Texture _texture; + std::string _resourcePath; + INTERNAL: //! @return libray Texture struct operator ::Texture() const; diff --git a/lib/Ray/sources/Font.cpp b/lib/Ray/sources/Font.cpp index a619cd55..00711def 100644 --- a/lib/Ray/sources/Font.cpp +++ b/lib/Ray/sources/Font.cpp @@ -17,18 +17,6 @@ RAY::Font::Font() } RAY::Font::~Font() -{ - this->unload(); -} - -bool RAY::Font::load(const std::string &filename) -{ - this->_font = LoadFont(filename.c_str()); - return true; -} - -bool RAY::Font::unload() { UnloadFont(this->_font); - return true; } diff --git a/lib/Ray/sources/Font.hpp b/lib/Ray/sources/Font.hpp index 5b467e96..1ad65a1e 100644 --- a/lib/Ray/sources/Font.hpp +++ b/lib/Ray/sources/Font.hpp @@ -9,12 +9,12 @@ #define FONT_HPP_ #include -#include "IRessource.hpp" +#include namespace RAY { //! @brief A font manager - class Font: public IRessource { + class Font { public: //! @brief Create an font, loading a file //! @param filename: path to file to load @@ -32,13 +32,6 @@ namespace RAY //! @brief Unload font at destruction ~Font(); - //! @brief load font from file - //! @param filename: path of input - bool load(const std::string &filename); - - //! @brief unload ressources - bool unload(); - protected: private: //! @brief Font, really, that's just it... diff --git a/lib/Ray/sources/IRessource.hpp b/lib/Ray/sources/IRessource.hpp deleted file mode 100644 index 2482cc3c..00000000 --- a/lib/Ray/sources/IRessource.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* -** EPITECH PROJECT, 2021 -** Bomberman -** File description: -** Ressource -*/ - -#ifndef RESSOURCE_HPP_ -#define RESSOURCE_HPP_ - -#include - -namespace RAY { - //! @brief A Ressource interface - class IRessource { - public: - virtual ~IRessource() = default; - - virtual bool load(const std::string &filePath) = 0; - - virtual bool unload() = 0; - }; -}; - -#endif /* !RESSOURCE_HPP_ */ diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 1ca82650..cb4cd024 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -8,122 +8,102 @@ #include "Model/Model.hpp" #include "Exceptions/RayError.hpp" -RAY::Drawables::Drawables3D::Model::Model(const std::string &filename, - std::optional> texture, - const RAY::Vector3 &position, - const RAY::Vector3 &rotationAxis, - float rotationAngle, - const RAY::Vector3 &scale) - : ADrawable3D(position, WHITE), - _model(LoadModel(filename.c_str())), - _rotationAxis(rotationAxis), - _rotationAngle(rotationAngle), - _scale(scale) -{ - if (texture.has_value()) - this->setTextureToMaterial(texture->first, texture->second); -} +namespace RAY::Drawables::Drawables3D { -RAY::Drawables::Drawables3D::Model::Model(const Mesh &mesh) -: ADrawable3D({0, 0, 0}, WHITE), _model(LoadModelFromMesh(mesh)) -{ -} + Model::Model(const std::string &filename, + std::optional> texture, + const RAY::Vector3 &position, + const RAY::Vector3 &rotationAxis, + float rotationAngle, + const RAY::Vector3 &scale) + : ADrawable3D(position, WHITE), + _model(LoadModel(filename.c_str())), + _rotationAxis(rotationAxis), + _rotationAngle(rotationAngle), + _scale(scale) + { + if (texture.has_value()) + this->setTextureToMaterial(texture->first, texture->second); + } -RAY::Drawables::Drawables3D::Model::~Model() -{ - this->unload(); -} + Model::Model(const Mesh &mesh) + : ADrawable3D({0, 0, 0}, WHITE), _model(LoadModelFromMesh(mesh)) + { + } -bool RAY::Drawables::Drawables3D::Model::load(const std::string &filename) -{ - this->_model = LoadModel(filename.c_str()); - return true; -} + Model::~Model() + { + UnloadModel(this->_model); + } -bool RAY::Drawables::Drawables3D::Model::load(const Mesh &mesh) -{ - this->_model = LoadModelFromMesh(mesh); - return true; -} + bool Model::unloadKeepMeshes() + { + UnloadModelKeepMeshes(_model); + return true; + } -bool RAY::Drawables::Drawables3D::Model::unload() -{ - UnloadModel(this->_model); - return true; -} + bool Model::setAnimation(const RAY::ModelAnimation &animation) + { + if (!IsModelAnimationValid(this->_model, animation)) + throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model"); + UpdateModelAnimation(this->_model, animation, animation.getFrameCounter()); + return true; + } -bool RAY::Drawables::Drawables3D::Model::unloadKeepMeshes() -{ - UnloadModelKeepMeshes(_model); - return true; -} + bool Model::setTextureToMaterial(Model::MaterialType materialType, const std::string &texturePath) + { + this->_textureList.emplace(materialType, texturePath); + SetMaterialTexture(&this->_model.materials[materialType], + materialType, + this->_textureList.at(materialType)); + return true; + } -bool RAY::Drawables::Drawables3D::Model::setAnimation(const RAY::ModelAnimation &animation) -{ - if (!IsModelAnimationValid(this->_model, animation)) - throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model"); - UpdateModelAnimation(this->_model, animation, animation.getFrameCounter()); - return true; -} + Model::operator ::Model() const + { + return this->_model; + } -bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const RAY::Texture &texture) -{ - this->_textureList[materialType] = texture; - SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]); - return true; -} + int Model::getBoneCount() const + { + return this->_model.boneCount; + } -bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const std::string &texturePath) -{ - this->_textureList.emplace(materialType, texturePath); - SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]); - return true; -} + Model &Model::setRotationAngle(float rotationAngle) + { + this->_rotationAngle = rotationAngle; + return *this; + } -RAY::Drawables::Drawables3D::Model::operator ::Model() const -{ - return this->_model; -} + float Model::getRotationAngle(void) + { + return this->_rotationAngle; + } -int RAY::Drawables::Drawables3D::Model::getBoneCount() const -{ - return this->_model.boneCount; -} + Model &Model::setRotationAxis(const RAY::Vector3 &scale) + { + this->_scale = scale; + return *this; + } -RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setRotationAngle(float rotationAngle) -{ - this->_rotationAngle = rotationAngle; - return *this; -} + const RAY::Vector3 &Model::getRotationAxis(void) + { + return this->_rotationAxis; + } -float RAY::Drawables::Drawables3D::Model::getRotationAngle(void) -{ - return this->_rotationAngle; -} + Model &Model::setScale(const RAY::Vector3 &scale) + { + this->_scale = scale; + return *this; + } -RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setRotationAxis(const RAY::Vector3 &scale) -{ - this->_scale = scale; - return *this; -} + const RAY::Vector3 &Model::getScale(void) + { + return this->_scale; + } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Model::getRotationAxis(void) -{ - return this->_rotationAxis; -} - -RAY::Drawables::Drawables3D::Model &RAY::Drawables::Drawables3D::Model::setScale(const RAY::Vector3 &scale) -{ - this->_scale = scale; - return *this; -} - -const RAY::Vector3 &RAY::Drawables::Drawables3D::Model::getScale(void) -{ - return this->_scale; -} - -void RAY::Drawables::Drawables3D::Model::drawOn(RAY::Window &) -{ - DrawModelEx(this->_model, this->_position, this->_rotationAxis, this->_rotationAngle, this->_scale, this->_color); + void Model::drawOn(RAY::Window &) + { + DrawModelEx(this->_model, this->_position, this->_rotationAxis, this->_rotationAngle, this->_scale, this->_color); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index 1f50119e..039304ae 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -8,7 +8,6 @@ #ifndef MODEL_HPP_ #define MODEL_HPP_ -#include "IRessource.hpp" #include "Drawables/Texture.hpp" #include "Drawables/ADrawable3D.hpp" #include "Model/ModelAnimation.hpp" @@ -19,7 +18,7 @@ namespace RAY::Drawables::Drawables3D { //! @brief Basic 3D Model type - class Model: public IRessource, public Drawables::ADrawable3D { + class Model: public Drawables::ADrawable3D { public: typedef ::MaterialMapIndex MaterialType; @@ -46,15 +45,6 @@ namespace RAY::Drawables::Drawables3D { //! @brief Model destructor, unloads all related data ~Model(); - //! @brief Load model from file (meshes and materials) - bool load(const std::string &filePath); - - //! @brief Load model from mesh (default materials) - bool load(const Mesh &mesh); - - //! @brief Unload model (including meshes) from memory (RAM and/or VRAM) - bool unload() override; - //! @brief Unload model (excluding meshes) from memory (RAM and/or VRAM) bool unloadKeepMeshes(); @@ -64,7 +54,6 @@ namespace RAY::Drawables::Drawables3D { //! @brief Sets a texture to the Nth material //! @param materielIndex The type of material to apply the texture to (serves as an index) //! @param texture the texture to apply - bool setTextureToMaterial(MaterialType materialType, const RAY::Texture &texture); bool setTextureToMaterial(MaterialType materialType, const std::string &texture); //! @return The number of bones in the model diff --git a/sources/Component/Renderer/Drawable3DComponent.hpp b/sources/Component/Renderer/Drawable3DComponent.hpp index 0f8de20e..e4f85321 100644 --- a/sources/Component/Renderer/Drawable3DComponent.hpp +++ b/sources/Component/Renderer/Drawable3DComponent.hpp @@ -6,6 +6,7 @@ #include "Component/Component.hpp" #include "Drawables/ADrawable3D.hpp" +#include "Model/Model.hpp" namespace BBM { diff --git a/sources/main.cpp b/sources/main.cpp index 111f0fd3..43dccd7d 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -45,91 +45,7 @@ std::string get_full_path(const std::string &color) return path; } -int demo() -{ - WAL::Wal wal; - const int screenWidth = 800; - const int screenHeight = 450; - auto iterator = textures.begin(); - const std::string modelPath = "assets/player/player.iqm"; - RAY::TraceLog::setLevel(LOG_WARNING); - RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE); - RAY::Image icon("assets/icon.png"); - RAY::Drawables::Drawables3D::Model model(modelPath, std::pair(MAP_DIFFUSE, "assets/player/blue.png")); - RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f), - RAY::Vector3(0.0f, 0.0f, 0.0f), - RAY::Vector3(0.0f, 1.0f, 0.0f), - 45.0f, CAMERA_PERSPECTIVE - ); - WAL::Entity entityPlayer("roger"); - RAY::Drawables::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); - BBM::Drawable3DComponent circleComponent(entityPlayer, circle); - BBM::Renderer3DSystem circleSystem; - - wal.addSystem(circleSystem); - entityPlayer.addComponent(circleComponent); - -// RAY::Texture texture(get_full_path(*iterator)); - RAY::ModelAnimations animations(modelPath); - RAY::Drawables::Drawables3D::Grid grid(10, 1.0f); - RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON); - size_t animationIndex = 0; - RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position - -// model.setTextureToMaterial(MAP_DIFFUSE, texture); - window.setIcon(icon); - camera.setMode(CAMERA_FREE); // Set free camera mode - - float y_rotation = 0; - window.setFPS(60); - - while (!window.shouldClose()) - { - camera.update(); - - // Play animation when spacebar is held down - if (RAY::Controller::Keyboard::isDown(KEY_SPACE)) - { - animations[animationIndex].incrementFrameCounter(); - model.setAnimation(animations[animationIndex]); - } - if (RAY::Controller::Keyboard::isReleased(KEY_UP)) - { - ++iterator; - if (iterator == textures.end()) - iterator = textures.begin(); -// texture.unload(); -// texture.load(get_full_path(*iterator)); -// model.setTextureToMaterial(MAP_DIFFUSE, texture); - } - if (RAY::Controller::Keyboard::isReleased(KEY_LEFT)) - { - animationIndex = --animationIndex % animations.getAnimationsCount(); - model.setAnimation(animations[animationIndex]); - } - if (RAY::Controller::Keyboard::isReleased(KEY_RIGHT)) - { - animationIndex = ++animationIndex % animations.getAnimationsCount(); - model.setAnimation(animations[animationIndex]); - } - window.draw(); - window.clear(); - window.useCamera(camera); - - model.drawOn(window);//, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f )); - - window.draw(grid); - window.draw(circle); - window.unuseCamera(); - window.draw(instructionText); - window.draw(); - } - window.close(); - - - return 0; -} void usage(const std::string &bin)