<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Memory_AnyVariantValue_h_
#define _Stroika_Foundation_Memory_AnyVariantValue_h_  1

#include    "../StroikaPreComp.h"

#include    <memory>
#include    <type_traits>

#include    "../Configuration/Common.h"



/**
 *  \file
 *
 *  \version    <a href="code_status.html#Alpha">Alpha</a>
 *
 *  TODO:
 *
 *      @todo   consider using stuff like remove_references and remove_const to 'normalize' the T type
 *              used here. Might make it a little easier to use.
 *
 *      @todo   Consider making operator T () less restrictive - and work if conertable. But then not
 *              sure how to get the right type (can I do decltype (GetType())??? - in other words make a T out of
 *              the type_info? I think not...
 *
 *
 *  Awknolwedgements:
 *      I came up with this idea before looking at the BOOST any code, but when I thought of it
 *      I first checked out what boost had that was similar. Before implementing, I looked at
 *      http://www.boost.org/doc/libs/1_54_0/doc/html/any.html
 */



namespace   Stroika {
    namespace   Foundation {
        namespace   Memory {


            /**
             * \brief
             *
             *  Simple variant-value object, but unlike @VariantValue, this can contain ANY type. That both
             *  limits its usefulness (cannot use it for stuff like streaming to XML because not enough is
             *  known about the constituent types), but expands cases of usefulness - like for example - to
             *  implement a @BlockingQueue<> of Command objects, where you have a bunch of differnt kinds of
             *  commands (objects). The party enquing messages needs to know the types, and the party dequing them
             *  does, but nobody else.
             *
             *  Example Rationale:
             *      Often in more complex applications, one wants to have a producer - consumer system, with type safety
             *      and some kind of generic message routing. For example - consider the idea of the SOAP Envelope / Body
             *      distinction.
             *
             *      This also can easily be constructed with the Stroika BlockingQueue<>.
             *
             *      If you want to have type safety on construction of the shared objects to be safely know about on
             *      two ends (the producer and the consumer) but want to have a layer of software in between that handles
             *      the routing (as with SOAP) - having the ability to genericify an object, and then undo that (could also use
             *      serializaiton) - can be handy.
             *
             *      Note - this CAN be accomplished using templates as the in-between routing layer. But that approach has a
             *      number of defects including:
             *          o   Very complex message routing libraries - all in tempaltes - are hard to use because of bad
             *              compiler diagnostics when there is some mis-match.
             *
             *          o   Code bloat from complex/duplicative middle layers (routing layers).
             *
             *          o   Lack of modularity/hiding - all the template code needs to be in header files to be expanded.
             *
             *      Using AnyVariantValue can be a simple remedy to this. At the message routing (between producer/consumer) layer
             *      you wrap your objects in AnyVariantValue, and then (type safely) unpack them on the other end.
             *
             *  @see VariantValue
             */
            class   AnyVariantValue {
            public:
                AnyVariantValue ();
#if     qCompilerAndStdLib_Supports_ExplicitlyDeletedSpecialMembers
                AnyVariantValue (const AnyVariantValue& from) = default;
                AnyVariantValue& operator= (const AnyVariantValue& rhs) = default;
#else
                AnyVariantValue (const AnyVariantValue& from);
                AnyVariantValue& operator= (const AnyVariantValue& rhs);
#endif
                template    <typename   T>
                AnyVariantValue (T val);

            public:
                nonvirtual  const type_info&    GetType () const;

            public:
                /**
                 */
                nonvirtual  bool    empty () const;

            public:
                /**
                 */
                nonvirtual  void    clear ();

            public:
                /**
                 */
                template    <typename   RETURNTYPE>
#if qCompilerAndStdLib_Supports_ExplicitConversionOperators
                nonvirtual explicit operator RETURNTYPE () const;
#else
                nonvirtual operator RETURNTYPE () const;
#endif

            public:
                /**
                 */
                nonvirtual  bool    Equals (const AnyVariantValue& rhs) const;

            public:
                /**
                 */
                nonvirtual  bool    operator== (const AnyVariantValue& rhs) const;

            public:
                /**
                 */
                nonvirtual  bool    operator!= (const AnyVariantValue& rhs) const;

            private:
#if     !qCompilerAndStdLib_Supports_SharedPtrOfPrivateTypes<commit_msg>Comments<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Memory_AnyVariantValue_h_
#define _Stroika_Foundation_Memory_AnyVariantValue_h_  1

#include    "../StroikaPreComp.h"

#include    <memory>
#include    <type_traits>

#include    "../Configuration/Common.h"



/**
 *  \file
 *
 *  \version    <a href="code_status.html#Alpha">Alpha</a>
 *
 *  TODO:
 *
 *      @todo   Lose static cast stuff - and instead use As<> - for consistency with the rest
 *              of Stroika. Document (in some overall design doc) - the choice of As<> versus
 *              explicit conversion operator. I THINK the rationale is that:
 *                  static_cast<T> (n) is about the same as n.As<T> () - except that overload
 *                  semantics work better for static_cast<T> (n) - THINK ABOUT THIS - verus
 *                  .As<T> () is somewhat shorter, and more clear, and works with compilers that
 *                  dont have explicit operators.
 *
 *      @todo   consider using stuff like remove_references and remove_const to 'normalize' the T type
 *              used here. Might make it a little easier to use.
 *
 *      @todo   Consider making operator T () less restrictive - and work if conertable. But then not
 *              sure how to get the right type (can I do decltype (GetType())??? - in other words make a T out of
 *              the type_info? I think not...
 *
 *
 *  Awknolwedgements:
 *      I came up with this idea before looking at the BOOST any code, but when I thought of it
 *      I first checked out what boost had that was similar. Before implementing, I looked at
 *      http://www.boost.org/doc/libs/1_54_0/doc/html/any.html
 */



namespace   Stroika {
    namespace   Foundation {
        namespace   Memory {


            /**
             * \brief
             *
             *  Simple variant-value object, but unlike @VariantValue, this can contain ANY type. That both
             *  limits its usefulness (cannot use it for stuff like streaming to XML because not enough is
             *  known about the constituent types), but expands cases of usefulness - like for example - to
             *  implement a @BlockingQueue<> of Command objects, where you have a bunch of differnt kinds of
             *  commands (objects). The party enquing messages needs to know the types, and the party dequing them
             *  does, but nobody else.
             *
             *  Example Rationale:
             *      Often in more complex applications, one wants to have a producer - consumer system, with type safety
             *      and some kind of generic message routing. For example - consider the idea of the SOAP Envelope / Body
             *      distinction.
             *
             *      This also can easily be constructed with the Stroika BlockingQueue<>.
             *
             *      If you want to have type safety on construction of the shared objects to be safely know about on
             *      two ends (the producer and the consumer) but want to have a layer of software in between that handles
             *      the routing (as with SOAP) - having the ability to genericify an object, and then undo that (could also use
             *      serializaiton) - can be handy.
             *
             *      Note - this CAN be accomplished using templates as the in-between routing layer. But that approach has a
             *      number of defects including:
             *          o   Very complex message routing libraries - all in tempaltes - are hard to use because of bad
             *              compiler diagnostics when there is some mis-match.
             *
             *          o   Code bloat from complex/duplicative middle layers (routing layers).
             *
             *          o   Lack of modularity/hiding - all the template code needs to be in header files to be expanded.
             *
             *      Using AnyVariantValue can be a simple remedy to this. At the message routing (between producer/consumer) layer
             *      you wrap your objects in AnyVariantValue, and then (type safely) unpack them on the other end.
             *
             *  @see VariantValue
             */
            class   AnyVariantValue {
            public:
                AnyVariantValue ();
#if     qCompilerAndStdLib_Supports_ExplicitlyDeletedSpecialMembers
                AnyVariantValue (const AnyVariantValue& from) = default;
                AnyVariantValue& operator= (const AnyVariantValue& rhs) = default;
#else
                AnyVariantValue (const AnyVariantValue& from);
                AnyVariantValue& operator= (const AnyVariantValue& rhs);
#endif
                template    <typename   T>
                AnyVariantValue (T val);

            public:
                nonvirtual  const type_info&    GetType () const;

            public:
                /**
                 */
                nonvirtual  bool    empty () const;

            public:
                /**
                 */
                nonvirtual  void    clear ();

            public:
                /**
                 */
                template    <typename   RETURNTYPE>
#if     qCompilerAndStdLib_Supports_ExplicitConversionOperators
                nonvirtual explicit operator RETURNTYPE () const;
#else
                nonvirtual operator RETURNTYPE () const;
#endif

            public:
                /**
                 */
                nonvirtual  bool    Equals (const AnyVariantValue& rhs) const;

            public:
                /**
                 */
                nonvirtual  bool    operator== (const AnyVariantValue& rhs) const;

            public:
                /**
                 */
                nonvirtual  bool    operator!= (const AnyVariantValue& rhs) const;

            private:
#if     !qCompilerAndStdLib_Supports_SharedPtrOfPrivateTypes
{'fraction_non_alphanumeric': 0.062411971830985916, 'fraction_numerical': 0.002288732394366197, 'mean_word_length': 1.6457848160223567, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '675542', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2688, 'n_words': 1102}