Program Listing for File EntityWithMetadata.hpp

Return to documentation for file (include/nix/base/EntityWithMetadata.hpp)

// Copyright (c) 2013, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.

#ifndef NIX_ENTITY_WITH_METADATA_H
#define NIX_ENTITY_WITH_METADATA_H

#include <nix/base/NamedEntity.hpp>
#include <nix/Section.hpp>

namespace nix {
namespace base {

template <typename T>
class EntityWithMetadata : public NamedEntity<T> {

public:

    EntityWithMetadata()
        : NamedEntity<T>()
    {
    }

    EntityWithMetadata(const std::shared_ptr<T> &p_impl)
        : NamedEntity<T>(p_impl)
    {
    }

    EntityWithMetadata(std::shared_ptr<T> &&ptr)
        : NamedEntity<T>(std::move(ptr))
    {
    }

    Section metadata() const {
        return NamedEntity<T>::backend()->metadata();
    }

    void metadata(const Section &metadata) {
        if(metadata == none){
            NamedEntity<T>::backend()->metadata(none);
        }
        else{
            NamedEntity<T>::backend()->metadata(metadata.id());
        }
    }

    void metadata(const std::string &id) {
        NamedEntity<T>::backend()->metadata(id);
    }

    void metadata(const none_t t) {
        NamedEntity<T>::backend()->metadata(t);
    }

    virtual ~EntityWithMetadata() {}

};


} // namespace base
} // namespace nix

#endif // NIX_ENTITY_WITH_METADATA_H