<commit_before>/** \file   DirectoryEntry.h
 *  \brief  Interface for the DirectoryEntry class.
 *  \author Dr. <NAME> (<EMAIL>)
 *
 *  \copyright 2014 Universitätsbiblothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef DIRECTORY_ENTRY_H
#define DIRECTORY_ENTRY_H


#include <string>
#include <utility>
#include <vector>
#include "StringUtil.h"
#include "MarcTag.h"


/** \class DirectoryEntry
 *  \brief Encapsulates a MARC-21 directory entry.
 */
class DirectoryEntry {
public:
    static const size_t DIRECTORY_ENTRY_LENGTH; //< The fixed length of a directory entry according to the standard.
    static const size_t TAG_LENGTH;             //< The fixed length of a field tag according to the standard.
private:
    MarcTag tag_;
    unsigned field_length_;
    unsigned field_offset_;
public:
    /** Constructs a DirectoryEntry from the binary representation of a MARC-21 directory entry. */
    explicit DirectoryEntry(const std::string &raw_entry);

    /** Copy constructor. */
    DirectoryEntry(const DirectoryEntry &other)
        : tag_(other.tag_), field_length_(other.field_length_), field_offset_(other.field_offset_) { }

    /** Move constructor. */
    DirectoryEntry(DirectoryEntry &&other)
        : tag_(other.tag_), field_length_(other.field_length_), field_offset_(other.field_offset_) {}

    /** \brief Constructs a DirectoryEntry from its component parts.
     *
     *  \param tag           A field tag.  Must have a length of 3.
     *  \param field_length  Must be less than 10,000.
     *  \param field_offset  Must be less than 10,000.
     */
    DirectoryEntry(const MarcTag &tag, const unsigned field_length, const unsigned field_offset)
        : tag_(tag), field_length_(field_length), field_offset_(field_offset) {}

    inline DirectoryEntry &operator=(DirectoryEntry &&other) {
        tag_ = std::move(other.tag_);
        field_length_ = other.field_length_;
        field_offset_ = other.field_offset_;
        return *this;
    }

    /** Copy-assignment operator. */
    DirectoryEntry &operator=(const DirectoryEntry &rhs);

    const MarcTag &getTag() const { return tag_; }

    /** Includes the field terminator. */
    unsigned getFieldLength() const { return field_length_; }

    /** \param new_field_length  Must be less than 10,000 and must include the field terminator. */
    void setFieldLength(const unsigned new_field_length) { field_length_ = new_field_length; }

    unsigned getFieldOffset() const { return field_offset_; }

    /** \param new_field_offset  Must be less than 10,000. */
    void setFieldOffset(const unsigned new_field_offset) { field_offset_ = new_field_offset; }

    /** \return True if this DirectoryEntry corresponds to a control field, else false. */
    bool isControlFieldEntry() const { return tag_.isTagOfControlField(); }
<commit_msg>Don't use placement-new when you'ere too stupid to understand its implications! :-(<commit_after>/** \file   DirectoryEntry.h
 *  \brief  Interface for the DirectoryEntry class.
 *  \author Dr. <NAME> (<EMAIL>)
 *
 *  \copyright 2014 Universitätsbiblothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef DIRECTORY_ENTRY_H
#define DIRECTORY_ENTRY_H


#include <string>
#include <utility>
#include <vector>
#include "StringUtil.h"
#include "MarcTag.h"


/** \class DirectoryEntry
 *  \brief Encapsulates a MARC-21 directory entry.
 */
class DirectoryEntry {
public:
    static const size_t DIRECTORY_ENTRY_LENGTH; //< The fixed length of a directory entry according to the standard.
    static const size_t TAG_LENGTH;             //< The fixed length of a field tag according to the standard.
private:
    MarcTag tag_;
    unsigned field_length_;
    unsigned field_offset_;
public:
    /** Constructs a DirectoryEntry from the binary representation of a MARC-21 directory entry. */
    explicit DirectoryEntry(const std::string &raw_entry);

    /** Copy constructor. */
    DirectoryEntry(const DirectoryEntry &other)
        : tag_(other.tag_), field_length_(other.field_length_), field_offset_(other.field_offset_) { }

    /** Move constructor. */
    DirectoryEntry(DirectoryEntry &&other)
        : tag_(other.tag_), field_length_(other.field_length_), field_offset_(other.field_offset_) {}

    /** \brief Constructs a DirectoryEntry from its component parts.
     *
     *  \param tag           A field tag.  Must have a length of 3.
     *  \param field_length  Must be less than 10,000.
     *  \param field_offset  Must be less than 10,000.
     */
    DirectoryEntry(const MarcTag &tag, const unsigned field_length, const unsigned field_offset)
        : tag_(tag), field_length_(field_length), field_offset_(field_offset) {}

    inline DirectoryEntry &operator=(DirectoryEntry &&other) {
        tag_ = std::move(other.tag_);
        field_length_ = other.field_length_;
        field_offset_ = other.field_offset_;
        return *this;
    }

    /** Copy-assignment operator. */
    DirectoryEntry &operator=(const DirectoryEntry &rhs);

    inline void swap(DirectoryEntry &other) {
        std::swap(tag_, other.tag_);
        std::swap(field_length_, other.field_length_);
        std::swap(field_offset_, other.field_offset_);
    }
    
    const MarcTag &getTag() const { return tag_; }

    /** Includes the field terminator. */
    unsigned getFieldLength() const { return field_length_; }

    /** \param new_field_length  Must be less than 10,000 and must include the field terminator. */
    void setFieldLength(const unsigned new_field_length) { field_length_ = new_field_length; }

    unsigned getFieldOffset() const { return field_offset_; }

    /** \param new_field_offset  Must be less than 10,000. */
    void setFieldOffset(const unsigned new_field_offset) { field_offset_ = new_field_offset; }

    /** \return True if this DirectoryEntry corresponds to a control field, else false. */
    bool isControlFieldEntry() const { return tag_.isTagOfControlField(); }

{'fraction_non_alphanumeric': 0.08887362637362638, 'fraction_numerical': 0.008241758241758242, 'mean_word_length': 3.4723587223587224, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865512', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1989, 'n_words': 717}