<commit_before>/*
 * Copyright (c) 2017 <NAME>
 *
 * This file is part of the Realms Of Steel.
 * For conditions of distribution and use, see copyright details in the LICENSE file.
 */
#ifndef ROS_RESOURCE_H
#define ROS_RESOURCE_H

#include <core/Common.h>
#include <core/Environment.h>
#include <application/Logger.h>
#include <resources/ResourceCache.h>

namespace ros {
    template<class DerivedBuffer>
    class Resource {
        public:
            typedef boost::shared_ptr<DerivedBuffer> DerivedBufferPtr;

            Resource() { }
            explicit Resource(const std::string& name) {
                acquire(name);
            }

            virtual ~Resource() {
                release();
            }

            bool acquire(const std::string& name) {
                release();

                BufferPtr buffer = ResourceCache::getInstance()->acquireBuffer(name);
                if (!buffer) {
                    return false;
                }

                DerivedBufferPtr cast = boost::dynamic_pointer_cast<DerivedBuffer>(buffer);
                if (!cast) {
                    Logger::report(LogLevel_Critical, boost::format("Invalid buffer requested for resource %s") % name);
                    return false;
                }

                this->buffer = cast;
                return true;
            }

            void release() {
                if (buffer && buffer.unique()) {
                    ResourceCache::getInstance()->releaseBuffer(buffer);
                    buffer.reset();
                }
            }

            inline bool isNull() const { return !buffer; }
            inline operator bool() const { return !buffer; }

            inline DerivedBuffer& operator*() { return *buffer; }
            inline const DerivedBuffer& operator*() const { return *buffer; }
            inline DerivedBuffer* operator->() { return buffer.get(); }
            inline const DerivedBuffer* operator->() const { return buffer.get(); }

        private:
            DerivedBufferPtr buffer;
    };
}

#endif // ROS_RESOURCE_H
<commit_msg>Add typedef for RawResource<commit_after>/*
 * Copyright (c) 2017 <NAME>
 *
 * This file is part of the Realms Of Steel.
 * For conditions of distribution and use, see copyright details in the LICENSE file.
 */
#ifndef ROS_RESOURCE_H
#define ROS_RESOURCE_H

#include <core/Common.h>
#include <core/Environment.h>
#include <application/Logger.h>
#include <resources/ResourceCache.h>

namespace ros {
    template<class DerivedBuffer>
    class Resource {
        public:
            typedef boost::shared_ptr<DerivedBuffer> DerivedBufferPtr;

            Resource() { }
            explicit Resource(const std::string& name) {
                acquire(name);
            }

            virtual ~Resource() {
                release();
            }

            bool acquire(const std::string& name) {
                release();

                BufferPtr buffer = ResourceCache::getInstance()->acquireBuffer(name);
                if (!buffer) {
                    return false;
                }

                DerivedBufferPtr cast = boost::dynamic_pointer_cast<DerivedBuffer>(buffer);
                if (!cast) {
                    Logger::report(LogLevel_Critical, boost::format("Invalid buffer requested for resource %s") % name);
                    return false;
                }

                this->buffer = cast;
                return true;
            }

            void release() {
                if (buffer && buffer.unique()) {
                    ResourceCache::getInstance()->releaseBuffer(buffer);
                    buffer.reset();
                }
            }

            inline bool isNull() const { return !buffer; }
            inline operator bool() const { return !buffer; }

            inline DerivedBuffer& operator*() { return *buffer; }
            inline const DerivedBuffer& operator*() const { return *buffer; }
            inline DerivedBuffer* operator->() { return buffer.get(); }
            inline const DerivedBuffer* operator->() const { return buffer.get(); }

        private:
            DerivedBufferPtr buffer;
    };

    typedef Resource<RawBuffer> RawResource;
}

#endif // ROS_RESOURCE_H

{'fraction_non_alphanumeric': 0.10207449316360208, 'fraction_numerical': 0.001885902876001886, 'mean_word_length': 1.7659713168187745, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '652011', 'n_tokens_mistral': 1075, 'n_tokens_neox': 995, 'n_words': 280}