<commit_before>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef DA_CONFIGFILE_H
#define DA_CONFIGFILE_H

#include "giodevicebundlemanager.h"
#include "DataAccess/gfileiodevice.h"
#include "DataObjects/DataSet/datatable.h"
#include <QObject>
#include <QString>

namespace GUtil
{
    namespace Utils
    {
        class AbstractLogger;
    }

    namespace DataAccess
    {
        class GFileIODevice;
    }

    namespace BusinessObjects
    {
        // This class provices a persistent storage of variables.  You can store
        //   binary data as well as normal string data, because it translates strings
        //   into base64 before writing them to disk.

        class ConfigFile :
                public QObject,
                public Core::Interfaces::IUpdatable
        {
            Q_OBJECT
        public:

            explicit ConfigFile(const QString &, const QString &modifier = "",
                                QObject *parent = 0);
            explicit ConfigFile(const ConfigFile &, QObject *parent = 0);


            Custom::GVariant Value(const QString &key);
            QMap<QString, Custom::GVariant> Values(
                    const QStringList &keys = QStringList());

            void SetValue(const QString &key, const Custom::GVariant& value);
            void SetValues(const QMap<QString, Custom::GVariant> &);

            // Remove a specific key (or keys)
            void RemoveValue(const QString &);
            void RemoveValues(const QStringList &);

            bool Contains(const QString &key);

            void Clear();


            bool Reload();

            inline QString FileName() const{ return FileTransport().FileName(); }

            inline void GetIdentity(QString &identifier, QString &modifier) const{
                identifier = _identity;
                modifier = _modifier;
            }

            // If the configuration is supposed to be interfaced with humans,
            //  then set this to true.  It not, then the configuration will be
            //  in a compressed file that only the application can read.
            // Note: You must define "CRYPTOPP_COMPRESSION" in the preprocessor
            //  and link with libcryptopp.a to benefit from compression.
            PROPERTY(IsHumanReadable, bool);

            PROPERTY(AutoCommitChanges, bool);

            inline bool GetAsyncWrite() const{
                return _device_manager.GetAsyncWrite();
            }
            inline void SetAsyncWrite(bool b){
                _device_manager.SetAsyncWrite(b);
            }


        signals:

            void NotifyConfigurationUpdate();


        protected:

            inline DataAccess::GFileIODevice &FileTransport() {
                return (DataAccess::GFileIODevice &)_device_manager.Transport();
            }
            inline const DataAccess::GFileIODevice &FileTransport() const {
                return (const DataAccess::GFileIODevice &)_device_manager.Transport();
            }

            // IUpdatable interface:
            void commit_reject_changes(bool commit);


        protected slots:

            void new_input_data_arrived();


        private:

            QString _identity;
            QString _modifier;

            DataObjects::DataTable _table;

            QWaitCondition _condition_config_update;

            static QString get_file_location(QString id);
            void _init(const QString &, const QString &);

            // In case you want to do encryption/compression
            void _preprocess_outgoing_data(QByteArray &) const;
            void _preprocess_incoming_data(QByteArray &) const;

            void _init_new_table(DataObjects::DataTable &) const;

            void _value_changed();

            GIODeviceBundleManager _device_manager;

        };
    }
}

#endif // DA_CONFIGFILE_H
<commit_msg>Added macros for convenient subclassing<commit_after>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef DA_CONFIGFILE_H
#define DA_CONFIGFILE_H

#include "giodevicebundlemanager.h"
#include "DataAccess/gfileiodevice.h"
#include "DataObjects/DataSet/datatable.h"
#include <QObject>
#include <QString>


// Derived classes can make convenient property accessors with this macro
#define CONFIGFILE_PROPERTY( name, type ) \
    inline type Get##name() const{ return Value(#name).value<type>(); } \
    inline void Set##name(const type &value){ SetValue( #name, value ); } \
    enum{}



namespace GUtil
{
    namespace Utils
    {
        class AbstractLogger;
    }

    namespace DataAccess
    {
        class GFileIODevice;
    }

    namespace BusinessObjects
    {
        // This class provices a persistent storage of variables.  You can store
        //   binary data as well as normal string data, because it translates strings
        //   into base64 before writing them to disk.

        class ConfigFile :
                public QObject,
                public Core::Interfaces::IUpdatable
        {
            Q_OBJECT
        public:

            explicit ConfigFile(const QString &, const QString &modifier = "",
                                QObject *parent = 0);
            explicit ConfigFile(const ConfigFile &, QObject *parent = 0);


            Custom::GVariant Value(const QString &key);
            QMap<QString, Custom::GVariant> Values(
                    const QStringList &keys = QStringList());

            void SetValue(const QString &key, const Custom::GVariant& value);
            void SetValues(const QMap<QString, Custom::GVariant> &);

            // Remove a specific key (or keys)
            void RemoveValue(const QString &);
            void RemoveValues(const QStringList &);

            bool Contains(const QString &key);

            void Clear();


            bool Reload();

            inline QString FileName() const{ return FileTransport().FileName(); }

            inline void GetIdentity(QString &identifier, QString &modifier) const{
                identifier = _identity;
                modifier = _modifier;
            }

            // If the configuration is supposed to be interfaced with humans,
            //  then set this to true.  It not, then the configuration will be
            //  in a compressed file that only the application can read.
            // Note: You must define "CRYPTOPP_COMPRESSION" in the preprocessor
            //  and link with libcryptopp.a to benefit from compression.
            PROPERTY(IsHumanReadable, bool);

            PROPERTY(AutoCommitChanges, bool);

            inline bool GetAsyncWrite() const{
                return _device_manager.GetAsyncWrite();
            }
            inline void SetAsyncWrite(bool b){
                _device_manager.SetAsyncWrite(b);
            }


        signals:

            void NotifyConfigurationUpdate();


        protected:

            inline DataAccess::GFileIODevice &FileTransport() {
                return (DataAccess::GFileIODevice &)_device_manager.Transport();
            }
            inline const DataAccess::GFileIODevice &FileTransport() const {
                return (const DataAccess::GFileIODevice &)_device_manager.Transport();
            }

            // IUpdatable interface:
            void commit_reject_changes(bool commit);


        protected slots:

            void new_input_data_arrived();


        private:

            QString _identity;
            QString _modifier;

            DataObjects::DataTable _table;

            QWaitCondition _condition_config_update;

            static QString get_file_location(QString id);
            void _init(const QString &, const QString &);

            // In case you want to do encryption/compression
            void _preprocess_outgoing_data(QByteArray &) const;
            void _preprocess_incoming_data(QByteArray &) const;

            void _init_new_table(DataObjects::DataTable &) const;

            void _value_changed();

            GIODeviceBundleManager _device_manager;

        };
    }
}

#endif // DA_CONFIGFILE_H

{'fraction_non_alphanumeric': 0.07084760273972603, 'fraction_numerical': 0.0025684931506849314, 'mean_word_length': 1.9619651347068146, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '214231', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2255, 'n_words': 733}