<commit_before>/** \brief Interaction with the Zeder collaboration tool
 *  \author <NAME>
 *
 *  \copyright 2018 Universitätsbibliothek 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/>.
*/
#pragma once


#include <functional>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "IniFile.h"
#include "StringUtil.h"
#include "TimeUtil.h"
#include "util.h"


namespace Zeder {


enum Flavour { IXTHEO, KRIMDOK };


const std::unordered_map<Flavour, std::string> FLAVOUR_TO_STRING_MAP{
    { IXTHEO,   "IxTheo"  },
    { KRIMDOK,  "KrimDok" }
};


static constexpr auto MODIFIED_TIMESTAMP_FORMAT_STRING = "%Y-%m-%d %H:%M:%S";


// A basic entry in a Zeder spreadsheet
class Entry {
    using AttributeMap = std::unordered_map<std::string, std::string>;

    unsigned id_;
    tm last_modified_timestamp_;
    AttributeMap attributes_;     // column name => content
public:
    using iterator = AttributeMap::iterator;
    using const_iterator = AttributeMap::const_iterator;
public:
    explicit Entry(const unsigned id = 0): id_(id), last_modified_timestamp_{}, attributes_() {}

    unsigned getId() const { return id_; }
    void setId(unsigned id) { id_ = id; }
    const tm &getLastModifiedTimestamp() const { return last_modified_timestamp_; }
    void setModifiedTimestamp(const tm &timestamp) { std::memcpy(&last_modified_timestamp_, &timestamp, sizeof(timestamp)); }
    const std::string &getAttribute(const std::string &name) const;
    void setAttribute(const std::string &name, const std::string &value, bool overwrite = false);
    bool hasAttribute(const std::string &name) const { return attributes_.find(name) != attributes_.end(); }
    void removeAttribute(const std::string &name);
    unsigned keepAttributes(const std::vector<std::string> &names_to_keep);
    void prettyPrint(std::string * const print_buffer) const;

    const_iterator begin() const { return attributes_.begin(); }
    const_iterator end() const { return attributes_.end(); }
    size_t size() const { return attributes_.size(); }

    struct DiffResult {
        // True if the modified revision's timestamp is newer than the source revision's
        bool timestamp_is_newer;
        // ID of the corresponding entry
        unsigned id_;
        // Last modified timestamp of the modified/newer revision
        tm last_modified_timestamp_;<commit_msg>Fixed a CentOS inompatibility problem.<commit_after>/** \brief Interaction with the Zeder collaboration tool
 *  \author <NAME>
 *
 *  \copyright 2018 Universitätsbibliothek 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/>.
*/
#pragma once


#include <functional>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "IniFile.h"
#include "StringUtil.h"
#include "TimeUtil.h"
#include "util.h"


namespace Zeder {


enum Flavour { IXTHEO, KRIMDOK };


} // unnamed namespace


namespace std {
    template <>
    struct hash<Zeder::Flavour> {
        size_t operator()(const Zeder::Flavour &flavour) const {
            // hash method here.
            return hash<int>()(flavour);
        }
    };
} // namespace std


namespace Zeder {


const std::unordered_map<Flavour, std::string> FLAVOUR_TO_STRING_MAP{
    { IXTHEO,   "IxTheo"  },
    { KRIMDOK,  "KrimDok" }
};


static constexpr auto MODIFIED_TIMESTAMP_FORMAT_STRING = "%Y-%m-%d %H:%M:%S";


// A basic entry in a Zeder spreadsheet
class Entry {
    using AttributeMap = std::unordered_map<std::string, std::string>;

    unsigned id_;
    tm last_modified_timestamp_;
    AttributeMap attributes_;     // column name => content
public:
    using iterator = AttributeMap::iterator;
    using const_iterator = AttributeMap::const_iterator;
public:
    explicit Entry(const unsigned id = 0): id_(id), last_modified_timestamp_{}, attributes_() {}

    unsigned getId() const { return id_; }
    void setId(unsigned id) { id_ = id; }
    const tm &getLastModifiedTimestamp() const { return last_modified_timestamp_; }
    void setModifiedTimestamp(const tm &timestamp) { std::memcpy(&last_modified_timestamp_, &timestamp, sizeof(timestamp)); }
    const std::string &getAttribute(const std::string &name) const;
    void setAttribute(const std::string &name, const std::string &value, bool overwrite = false);
    bool hasAttribute(const std::string &name) const { return attributes_.find(name) != attributes_.end(); }
    void removeAttribute(const std::string &name);
    unsigned keepAttributes(const std::vector<std::string> &names_to_keep);
    void prettyPrint(std::string * const print_buffer) const;

    const_iterator begin() const { return attributes_.begin(); }
    const_iterator end() const { return attributes_.end(); }
    size_t size() const { return attributes_.size(); }

    struct DiffResult {
        // True if the modified revision's timestamp is newer than the source revision's
        bool timestamp_is_newer_;
        // ID of the corresponding entry
        unsigned id_;
        // Last modified timestamp of the modified/newer revision
        tm last_modified_timestamp_;
{'fraction_non_alphanumeric': 0.09899592092877314, 'fraction_numerical': 0.0018826482585503608, 'mean_word_length': 3.9189814814814814, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 26, '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': '3913421', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1774, 'n_words': 628}