<commit_before>#ifndef VALUE_H
#define VALUE_H
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

#include "proton/data.hpp"
#include "proton/decoder.hpp"
#include "proton/pn_unique_ptr.hpp"
#include "proton/types.hpp"

namespace proton {

class data;
class encoder;
class decoder;

/**
 * Holder for an AMQP value.
 *
 * proton::value can hold any AMQP data value, simple or compound.  It has
 * assignment and conversion operators to convert its contents easily to and
 * from native C++ types.
 *
 * See proton::encoder and proton::decoder for details of the conversion rules.
 * Assigning to a proton::value follows the encoder rules, converting from a
 * proton::value (or calling proton::value::get) follows the decoder rules.
 */
class value : public comparable<value> {
  public:
    PN_CPP_EXTERN value();
    PN_CPP_EXTERN value(const value& x);
    PN_CPP_EXTERN value(const data&);

    template <class T> value(const T& x) : data_(data::create()) { *data_ = x; }

    PN_CPP_EXTERN value& operator=(const value& x);
    PN_CPP_EXTERN value& operator=(const data& x);
    template <class T> value& operator=(const T& x) { *data_ = x; return *this; }

    PN_CPP_EXTERN void clear();
    PN_CPP_EXTERN bool empty() const;

    // FIXME aconway 2015-11-06: rename encode/decode

    /** Encoder to encode complex data into this value. Note this clears the value. */
    PN_CPP_EXTERN class encoder& encoder();

    /** Decoder to decode complex data from this value. Note this rewinds the decoder. */
    PN_CPP_EXTERN class decoder& decoder() const;

    /** Type of the current value*/
    PN_CPP_EXTERN type_id type() const;

    /** Get the value. */
    template<class T> void get(T &t) const { decoder() >> t; }

    /** Get the value. */
    template<class T> T get() const { T t; get(t); return t; }

    /** Automatic conversion */
    template<class T> operator T() const { return get<T>(); }

    PN_CPP_EXTERN bool operator==(const value& x) const;
    PN_CPP_EXTERN bool operator<(const value& x) const;

  friend PN_CPP_EXTERN class encoder& operator<<(class encoder& e, const value& dv);
  friend PN_CPP_EXTERN class decoder& operator>>(class decoder& d, value& dv);
  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const value& dv);

  private:
    pn_unique_ptr<data> data_;
  friend class message;<commit_msg>NO-JIRA: c++: remove incorrect FIXME comment.<commit_after>#ifndef VALUE_H
#define VALUE_H
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

#include "proton/data.hpp"
#include "proton/decoder.hpp"
#include "proton/pn_unique_ptr.hpp"
#include "proton/types.hpp"

namespace proton {

class data;
class encoder;
class decoder;

/**
 * Holder for an AMQP value.
 *
 * proton::value can hold any AMQP data value, simple or compound.  It has
 * assignment and conversion operators to convert its contents easily to and
 * from native C++ types.
 *
 * See proton::encoder and proton::decoder for details of the conversion rules.
 * Assigning to a proton::value follows the encoder rules, converting from a
 * proton::value (or calling proton::value::get) follows the decoder rules.
 */
class value : public comparable<value> {
  public:
    PN_CPP_EXTERN value();
    PN_CPP_EXTERN value(const value& x);
    PN_CPP_EXTERN value(const data&);

    template <class T> value(const T& x) : data_(data::create()) { *data_ = x; }

    PN_CPP_EXTERN value& operator=(const value& x);
    PN_CPP_EXTERN value& operator=(const data& x);
    template <class T> value& operator=(const T& x) { *data_ = x; return *this; }

    PN_CPP_EXTERN void clear();
    PN_CPP_EXTERN bool empty() const;

    /** Encoder to encode complex data into this value. Note this clears the value. */
    PN_CPP_EXTERN class encoder& encoder();

    /** Decoder to decode complex data from this value. Note this rewinds the decoder. */
    PN_CPP_EXTERN class decoder& decoder() const;

    /** Type of the current value*/
    PN_CPP_EXTERN type_id type() const;

    /** Get the value. */
    template<class T> void get(T &t) const { decoder() >> t; }

    /** Get the value. */
    template<class T> T get() const { T t; get(t); return t; }

    /** Automatic conversion */
    template<class T> operator T() const { return get<T>(); }

    PN_CPP_EXTERN bool operator==(const value& x) const;
    PN_CPP_EXTERN bool operator<(const value& x) const;

  friend PN_CPP_EXTERN class encoder& operator<<(class encoder& e, const value& dv);
  friend PN_CPP_EXTERN class decoder& operator>>(class decoder& d, value& dv);
  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const value& dv);

  private:
    pn_unique_ptr<data> data_;
  friend class message;
{'fraction_non_alphanumeric': 0.10162929504758832, 'fraction_numerical': 0.0025810614615260526, 'mean_word_length': 3.8361934477379096, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '5518177', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1774, 'n_words': 741}