Program Listing for File Section.hpp

Return to documentation for file (include/nix/Section.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_SECTION_H
#define NIX_SECTION_H

#include <nix/util/filter.hpp>
#include <nix/base/NamedEntity.hpp>
#include <nix/base/ISection.hpp>
#include <nix/Property.hpp>
#include <nix/DataType.hpp>
#include <nix/Platform.hpp>
#include <nix/types.hpp>
#include <nix/ObjectType.hpp>

#include <memory>
#include <functional>
#include <string>
#include <cstdlib>

namespace nix {


class NIXAPI Section : public base::NamedEntity<base::ISection> {

public:

    Section();

    Section(std::nullptr_t ptr);

    Section(const Section &other);

    Section(const std::shared_ptr<base::ISection> &p_impl);

    Section(std::shared_ptr<base::ISection> &&ptr);

    //--------------------------------------------------
    // Attribute getter and setter
    //--------------------------------------------------

    void repository(const std::string &repository);

    boost::optional<std::string> repository() const {
        return backend()->repository();
    }

    void repository(const boost::none_t t) {
        backend()->repository(t);
    }

    void link(const std::string &id);

    void link(const Section &link);

    Section link() const {
        return backend()->link();
    }

    void link(const boost::none_t t) {
        backend()->link(t);
    }

    //--------------------------------------------------
    // Methods for parent access
    //--------------------------------------------------

    Section parent() const {
        return backend()->parent();
    }

    //--------------------------------------------------
    // Methods for child section access
    //--------------------------------------------------

    ndsize_t sectionCount() const {
        return backend()->sectionCount();
    }

    bool hasSection(const std::string &name_or_id) const {
        return backend()->hasSection(name_or_id);
    }

    bool hasSection(const Section &section) const;

    Section getSection(const std::string &name_or_id) const {
        return backend()->getSection(name_or_id);
    }

    virtual Section getSection(ndsize_t index) const;

    std::vector<Section> sections(const util::Filter<Section>::type &filter = util::AcceptAll<Section>()) const;

    std::vector<Section> findSections(const util::Filter<Section>::type &filter = util::AcceptAll<Section>(),
                                      size_t max_depth = std::numeric_limits<size_t>::max()) const;

    std::vector<Section> findRelated(const util::Filter<Section>::type &filter = util::AcceptAll<Section>()) const;

    Section createSection(const std::string &name, const std::string &type);

    bool deleteSection(const std::string &name_or_id) {
        return backend()->deleteSection(name_or_id);
    }

    bool deleteSection(const Section &section);

    //--------------------------------------------------
    // Methods for property access
    //--------------------------------------------------

    ndsize_t propertyCount() const {
        return backend()->propertyCount();
    }

    bool hasProperty(const std::string &name_or_id) const {
        return backend()->hasProperty(name_or_id);
    }

    bool hasProperty(const Property &property) const;

    Property getProperty(const std::string &name_or_id) const {
        return backend()->getProperty(name_or_id);
    }

    Property getProperty(ndsize_t index) const {
        return backend()->getProperty(index);
    }

    std::vector<Property> properties(const util::Filter<Property>::type &filter=util::AcceptAll<Property>()) const;

    std::vector<Property> inheritedProperties() const;

    Property createProperty(const std::string &name, const DataType &dtype);

    Property createProperty(const std::string &name, const Variant &value);

    Property createProperty(const std::string &name, const std::vector<Variant> &values);

    bool deleteProperty(const std::string &name_or_id) {
        return backend()->deleteProperty(name_or_id);
    }

    bool deleteProperty(const Property &property);

    //--------------------------------------------------
    // Other methods and functions
    //--------------------------------------------------

    std::vector<nix::DataArray> referringDataArrays(const nix::Block &b) const;

    std::vector<nix::DataArray> referringDataArrays() const;


    std::vector<nix::Tag> referringTags() const;


    std::vector<nix::Tag> referringTags(const nix::Block &b) const;


    std::vector<nix::MultiTag> referringMultiTags() const;


    std::vector<nix::MultiTag> referringMultiTags(const nix::Block &b) const;


    std::vector<nix::Source> referringSources() const;


    std::vector<nix::Source> referringSources(const nix::Block &b) const;

    std::vector<nix::Block> referringBlocks() const;

    Section &operator=(const none_t &t) {
        ImplContainer::operator=(t);
        return *this;
    }

    Section &operator=(const Section &other)  {
        ImplContainer::operator=(other);
        return *this;
    }

    NIXAPI friend std::ostream& operator<<(std::ostream &out, const Section &ent);

private:

    std::vector<Section> findDownstream(const std::function<bool(Section)> &filter) const;

    std::vector<Section> findAmongParents(const std::function<bool(Section)> &filter) const;

    std::vector<Section> findSideways(const std::function<bool(Section)> &filter, const std::string &caller_id) const;

    size_t tree_depth() const;
};

template<>
struct objectToType<nix::Section> {
    static const bool isValid = true;
    static const ObjectType value = ObjectType::Section;
    typedef nix::base::ISection backendType;
};

NIXAPI std::ostream& operator<<(std::ostream &out, const Section &ent);

} // namespace nix

#endif // NIX_SECTION_H