<commit_before>/**
 *  Class describing a (mid-level) AMQP channel implementation
 *
 *  @copyright 2014 - 2018 Copernica BV
 */

/**
 *  Include guard
 */
#pragma once

/**
 *  Set up namespace
 */
namespace AMQP {

/**
 *  Class definition
 */
class Channel
{
private:
    /**
     *  The implementation for the channel
     *  @var    std::unique_ptr<ChannelImpl>
     */
    std::shared_ptr<ChannelImpl> _implementation;

public:
    /**
     *  Construct a channel object
     * 
     *  The passed in connection pointer must remain valid for the 
     *  lifetime of the channel. Watch out: this method throws an error
     *  if the channel could not be constructed (for example because the
     *  max number of AMQP channels has been reached)
     * 
     *  @param  connection
     *  @throws std::runtime_error
     */
    Channel(Connection *connection);
    
    /**
     *  Copy'ing of channel objects is not supported
     *  @param  channel
     */
    Channel(const Channel &channel) = delete;

    /**
     *  But movement _is_ allowed
     *  @param  channel
     */
    Channel(Channel &&channel) : _implementation(std::move(channel._implementation)) {}

    /**
     *  Destructor
     */
    virtual ~Channel() 
    {
        // close the channel (this will eventually destruct the channel)
        _implementation->close();
    }

    /**
     *  No assignments of other channels
     *  @param  channel
     *  @return Channel
     */
    Channel &operator=(const Channel &channel) = delete;

    /**
     *  Callback that is called when the channel was succesfully created.
     *
     *  Only one callback can be registered. Calling this function multiple
     *  times will remove the old callback.
     *
     *  @param  callback    the callback to execute
     */
    void onReady(const SuccessCallback &callback)
    {
        _implementation->onReady(callback);
    }

    /**
     *  Callback that is called when an error occurs.<commit_msg>fix bug in Channel destructor for objects that were already moved<commit_after>/**
 *  Class describing a (mid-level) AMQP channel implementation
 *
 *  @copyright 2014 - 2018 Copernica BV
 */

/**
 *  Include guard
 */
#pragma once

/**
 *  Set up namespace
 */
namespace AMQP {

/**
 *  Class definition
 */
class Channel
{
private:
    /**
     *  The implementation for the channel
     *  @var    std::shared_ptr<ChannelImpl>
     */
    std::shared_ptr<ChannelImpl> _implementation;

public:
    /**
     *  Construct a channel object
     * 
     *  The passed in connection pointer must remain valid for the 
     *  lifetime of the channel. Watch out: this method throws an error
     *  if the channel could not be constructed (for example because the
     *  max number of AMQP channels has been reached)
     * 
     *  @param  connection
     *  @throws std::runtime_error
     */
    Channel(Connection *connection);
    
    /**
     *  Copy'ing of channel objects is not supported
     *  @param  channel
     */
    Channel(const Channel &channel) = delete;

    /**
     *  But movement _is_ allowed
     *  @param  channel
     */
    Channel(Channel &&channel) : _implementation(std::move(channel._implementation)) {}

    /**
     *  Destructor
     */
    virtual ~Channel() 
    {
        // close the channel (this will eventually destruct the channel)
        // note that the channel may be in an invalid state in case it was moved, hence the "if"
        if (_implementation) _implementation->close();
    }

    /**
     *  No assignments of other channels
     *  @param  channel
     *  @return Channel
     */
    Channel &operator=(const Channel &channel) = delete;

    /**
     *  Callback that is called when the channel was succesfully created.
     *
     *  Only one callback can be registered. Calling this function multiple
     *  times will remove the old callback.
     *
     *  @param  callback    the callback to execute
     */
    void onReady(const SuccessCallback &callback)
    {
        _implementation->onReady(callback);
    }

    /**
     *  Callback that is called when an error occurs.
{'fraction_non_alphanumeric': 0.09159378036929057, 'fraction_numerical': 0.003887269193391642, 'mean_word_length': 2.2519747235387046, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3679115', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1108, 'n_words': 391}