<commit_before>// 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.

#include <nix/hdf5/Group.hpp>
#include <boost/multi_array.hpp>

namespace nix {
namespace hdf5 {


Group::Group()
    : h5group()
{}


Group::Group(H5::Group h5group)
    : h5group(h5group)
{}


Group::Group(const Group &group)
    : h5group(group.h5group)
{}


Group& Group::operator=(const Group &group)
{
    h5group = group.h5group;
    return *this;
}


bool Group::hasAttr(const std::string &name) const {
    return H5Aexists(h5group.getId(), name.c_str());
}


void Group::removeAttr(const std::string &name) const {
    h5group.removeAttr(name);
}


bool Group::hasObject(const std::string &name) const {
    // empty string should return false, not exception (which H5Lexists would)
    if (name.empty()) {
        return false;
    }
    htri_t res = H5Lexists(h5group.getLocId(), name.c_str(), H5P_DEFAULT);
    return res;
}


size_t Group::objectCount() const {
    return h5group.getNumObjs();
}


std::string Group::objectName(size_t index) const {
    std::string str_name;
    // check whether name is found by index
    ssize_t name_len = H5Lget_name_by_idx(h5group.getLocId(),
                                                  ".",
                                                  H5_INDEX_NAME,
                                                  H5_ITER_NATIVE,<commit_msg>Modified Group.cpp to check index before calling H5Lget_name_by_idx<commit_after>// 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.

#include <nix/hdf5/Group.hpp>
#include <boost/multi_array.hpp>

namespace nix {
namespace hdf5 {


Group::Group()
    : h5group()
{}


Group::Group(H5::Group h5group)
    : h5group(h5group)
{}


Group::Group(const Group &group)
    : h5group(group.h5group)
{}


Group& Group::operator=(const Group &group)
{
    h5group = group.h5group;
    return *this;
}


bool Group::hasAttr(const std::string &name) const {
    return H5Aexists(h5group.getId(), name.c_str());
}


void Group::removeAttr(const std::string &name) const {
    h5group.removeAttr(name);
}


bool Group::hasObject(const std::string &name) const {
    // empty string should return false, not exception (which H5Lexists would)
    if (name.empty()) {
        return false;
    }
    htri_t res = H5Lexists(h5group.getLocId(), name.c_str(), H5P_DEFAULT);
    return res;
}


size_t Group::objectCount() const {
    return h5group.getNumObjs();
}


std::string Group::objectName(size_t index) const {
    // check if index valid
    if(index > objectCount()) {
        throw OutOfBounds("No data array at given index", index);
    }
    
    std::string str_name;
    // check whether name is found by index
    ssize_t name_len = H5Lget_name_by_idx(h5group.getLocId(),
                                                  ".",
                                                  H5_INDEX_NAME,
                                                  H5_ITER_NATIVE,
{'fraction_non_alphanumeric': 0.1159678858162355, 'fraction_numerical': 0.016354445435622957, 'mean_word_length': 2.594017094017094, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '465636', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1038, 'n_words': 278}