//
// LDASTools frameCPP - A library implementing the LIGO/Virgo frame
// specification
//
// Copyright (C) 2018-2020 California Institute of Technology
//
// LDASTools frameCPP is free software; you may redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 (GPLv2) of the
// License or at your discretion, any later version.
//
// LDASTools frameCPP is distributed in the hope that it will be useful, but
// without any warranty or even the implied warranty of merchantability
// or fitness for a particular purpose. See the GNU General Public
// License (GPLv2) for more details.
//
// Neither the names of the California Institute of Technology (Caltech),
// The Massachusetts Institute of Technology (M.I.T), The Laser
// Interferometer Gravitational-Wave Observatory (LIGO), nor the names
// of its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// You should have received a copy of the licensing terms for this
// software included in the file LICENSE located in the top-level
// directory of this package. If you did not, you can view a copy at
// http://dcc.ligo.org/M1500244/LICENSE
//

#ifndef FrameCPP_UNIVERSAL__FRIMPL__FrRawDataData_HH
#define FrameCPP_UNIVERSAL__FRIMPL__FrRawDataData_HH

#if defined( __cplusplus ) && !defined( SWIG )

#include "framecpp/Common/SearchContainer.hh"

#include "framecpp/Universal/FrAdcData.hh"
#include "framecpp/Universal/FrMsg.hh"
#include "framecpp/Universal/FrSerData.hh"
#include "framecpp/Universal/FrTable.hh"
#include "framecpp/Universal/FrVect.hh"

namespace FrameCPP
{
    namespace Universal
    {
        namespace FrRawDataImpl
        {
            class Data : public Impl::FrObjectMetaData< Data >
            {
            public:
                //-----------------------------------------------------
                // Legacy types
                //-----------------------------------------------------
                struct v3
                {
                    using name_type = std::string;
                    using firstSer_type =
                        Common::SearchContainer< FrSerData,
                                                 &FrSerData::GetNameSlow >;
                    using firstSer_iterator = firstSer_type::iterator;
                    using const_firstSer_iterator =
                        firstSer_type::const_iterator;
                    using firstSer_hash_iterator = firstSer_type::hash_iterator;
                    using const_firstSer_hash_iterator =
                        firstSer_type::const_hash_iterator;

                    using firstAdc_type =
                        Common::SearchContainer< FrAdcData,
                                                 &FrAdcData::GetNameSlow >;
                    using firstAdc_iterator = firstAdc_type::iterator;
                    using const_firstAdc_iterator =
                        firstAdc_type::const_iterator;
                    using firstAdc_hash_iterator = firstAdc_type::hash_iterator;
                    using const_firstAdc_hash_iterator =
                        firstAdc_type::const_hash_iterator;

                    using logMsg_type =
                        Common::SearchContainer< FrMsg, &FrMsg::GetAlarm >;
                    using logMsg_iterator = logMsg_type::iterator;
                    using const_logMsg_iterator = logMsg_type::const_iterator;
                    using logMsg_hash_iterator = logMsg_type::hash_iterator;
                    using const_logMsg_hash_iterator =
                        logMsg_type::const_hash_iterator;

                    using more_type =
                        Common::SearchContainer< FrVect, &FrVect::GetName >;
                    using more_iterator = more_type::iterator;
                    using const_more_iterator = more_type::const_iterator;
                    using more_hash_iterator = more_type::hash_iterator;
                    using const_more_hash_iterator =
                        more_type::const_hash_iterator;
                };
                struct v4
                {
                    using name_type = v3::name_type;
                    using firstSer_type = v3::firstSer_type;
                    using firstSer_iterator = v3::firstSer_iterator;
                    using const_firstSer_iterator = v3::const_firstSer_iterator;
                    using firstSer_hash_iterator = v3::firstSer_hash_iterator;
                    using const_firstSer_hash_iterator =
                        v3::const_firstSer_hash_iterator;

                    using firstAdc_type = v3::firstAdc_type;
                    using firstAdc_iterator = v3::firstAdc_iterator;
                    using const_firstAdc_iterator = v3::const_firstAdc_iterator;
                    using firstAdc_hash_iterator = v3::firstAdc_hash_iterator;
                    using const_firstAdc_hash_iterator =
                        v3::const_firstAdc_hash_iterator;

                    using firstTable_type =
                        Common::SearchContainer< FrTable,
                                                 &FrTable::GetNameSlow >;
                    using firstTable_iterator = firstTable_type::iterator;
                    using const_firstTable_iterator =
                        firstTable_type::const_iterator;
                    using firstTable_hash_iterator =
                        firstTable_type::hash_iterator;
                    using const_firstTable_hash_iterator =
                        firstTable_type::const_hash_iterator;

                    using logMsg_type = v3::logMsg_type;
                    using logMsg_iterator = v3::logMsg_iterator;
                    using const_logMsg_iterator = v3::const_logMsg_iterator;
                    using logMsg_hash_iterator = v3::logMsg_hash_iterator;
                    using const_logMsg_hash_iterator =
                        v3::const_logMsg_hash_iterator;

                    using more_type = v3::more_type;
                    using more_iterator = v3::more_iterator;
                    using const_more_iterator = v3::const_more_iterator;
                    using more_hash_iterator = v3::more_hash_iterator;
                    using const_more_hash_iterator =
                        v3::const_more_hash_iterator;
                };
                using v5 = v4;
                using v6 = v5;
                using v7 = v6;
                using v8 = v7;
                using v9 = v8;

                //-------------------------------------------------------

                using current_version = v9;

                using name_type = current_version::name_type;
                using firstSer_type = current_version::firstSer_type;
                using firstSer_iterator = current_version::firstSer_iterator;
                using const_firstSer_iterator =
                    current_version::const_firstSer_iterator;
                using firstSer_hash_iterator =
                    current_version::firstSer_hash_iterator;
                using const_firstSer_hash_iterator =
                    current_version::const_firstSer_hash_iterator;

                using firstAdc_type = current_version::firstAdc_type;
                using firstAdc_iterator = current_version::firstAdc_iterator;
                using const_firstAdc_iterator =
                    current_version::const_firstAdc_iterator;
                using firstAdc_hash_iterator =
                    current_version::firstAdc_hash_iterator;
                using const_firstAdc_hash_iterator =
                    current_version::const_firstAdc_hash_iterator;

                using firstTable_type = current_version::firstTable_type;
                using firstTable_iterator =
                    current_version::firstTable_iterator;
                using const_firstTable_iterator =
                    current_version::const_firstTable_iterator;
                using firstTable_hash_iterator =
                    current_version::firstTable_hash_iterator;
                using const_firstTable_hash_iterator =
                    current_version::const_firstTable_hash_iterator;

                using logMsg_type = current_version::logMsg_type;
                using logMsg_iterator = current_version::logMsg_iterator;
                using const_logMsg_iterator =
                    current_version::const_logMsg_iterator;
                using logMsg_hash_iterator =
                    current_version::logMsg_hash_iterator;
                using const_logMsg_hash_iterator =
                    current_version::const_logMsg_hash_iterator;

                using more_type = current_version::more_type;
                using more_iterator = current_version::more_iterator;
                using const_more_iterator =
                    current_version::const_more_iterator;
                using more_hash_iterator = current_version::more_hash_iterator;
                using const_more_hash_iterator =
                    current_version::const_more_hash_iterator;
                //-----------------------------------------------------------------
                /// @brief Nam eof raw data.
                ///
                /// @return
                ///   A constant reference to the name of the raw data
                ///   structure.
                //-----------------------------------------------------------------
                inline const name_type&
                GetName( ) const
                {
                    return ( name );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first serial data structure.
                ///
                /// \return
                ///     A constant reference to the first serial data structure.
                //-----------------------------------------------------------------
                inline const firstSer_type&
                RefFirstSer( ) const
                {
                    return ( firstSer );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first serial data structure.
                ///
                /// \return
                ///     A reference to the first serial data structure.
                //-----------------------------------------------------------------
                inline firstSer_type&
                RefFirstSer( )
                {
                    return ( firstSer );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first ADC data structure.
                ///
                /// \return
                ///     A constant reference to the first ADC data structure.
                //-----------------------------------------------------------------
                inline const firstAdc_type&
                RefFirstAdc( ) const
                {
                    return ( firstAdc );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first ADC data structure.
                ///
                /// \return
                ///     A reference to the first ADC data structure.
                //-----------------------------------------------------------------
                inline firstAdc_type&
                RefFirstAdc( )
                {
                    return ( firstAdc );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first table data structure.
                ///
                /// \return
                ///     A constant reference to the first table data structure.
                //-----------------------------------------------------------------
                inline const firstTable_type&
                RefFirstTable( ) const
                {
                    return ( firstTable );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first table data structure.
                ///
                /// \return
                ///     A reference to the first table data structure.
                //-----------------------------------------------------------------
                inline firstTable_type&
                RefFirstTable( )
                {
                    return ( firstTable );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first error message data structure.
                ///
                /// \return
                ///     A constant reference to the first error message data
                ///     structure.
                //-----------------------------------------------------------------
                inline const logMsg_type&
                RefLogMsg( ) const
                {
                    return ( logMsg );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for first error message data structure.
                ///
                /// \return
                ///     A reference to the first error message data structure.
                //-----------------------------------------------------------------
                inline logMsg_type&
                RefLogMsg( )
                {
                    return ( logMsg );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for additional user-defined data
                /// structure.
                ///
                /// \return
                ///     A constant reference to the additional user-defined data
                ///     structure.
                //-----------------------------------------------------------------
                inline const more_type&
                RefMore( ) const
                {
                    return ( more );
                }

                //-----------------------------------------------------------------
                /// \brief Identifier for additional user-defined data
                /// structure.
                ///
                /// \return
                ///     A reference to the additional user-defined data
                ///     structure.
                //-----------------------------------------------------------------
                inline more_type&
                RefMore( )
                {
                    return ( more );
                }

                inline bool
                operator==( const Data& RHS ) const
                {
                    return ( ( this == &RHS ) ||
                             ( ( name == RHS.name ) &&
                               ( firstSer == RHS.firstSer ) &&
                               ( firstAdc == RHS.firstAdc ) &&
                               ( firstTable == RHS.firstTable ) &&
                               ( logMsg == RHS.logMsg ) &&
                               ( more == RHS.more ) ) );
                }

            protected:
                //---------------------------------------------------------------
                /// Name of raw data.
                //---------------------------------------------------------------
                name_type name;
                //---------------------------------------------------------------
                /// Identifier for first serial data structure in the
                /// linked list.
                //---------------------------------------------------------------
                firstSer_type firstSer;
                //---------------------------------------------------------------
                /// Identifier for first ADC data structure in the
                /// linked list.
                //---------------------------------------------------------------
                firstAdc_type firstAdc;
                //---------------------------------------------------------------
                /// Identifier for first table data structure in the
                /// linked list.
                //---------------------------------------------------------------
                firstTable_type firstTable;
                //---------------------------------------------------------------
                /// Identifier for first error message data structure in the
                /// linked list.
                //---------------------------------------------------------------
                logMsg_type logMsg;
                //---------------------------------------------------------------
                /// Identifier for the additional user-defined data structure
                /// in the linked list.
                //---------------------------------------------------------------
                more_type more;
                //=======================================================
                //-------------------------------------------------------
                static constexpr unsigned int MAX_REF{ 5 };
            };

        }; // namespace FrRawDataImpl
    } // namespace Universal
} // namespace FrameCPP

FR_OBJECT_META_DATA_DECLARE_UNIVERSAL( FrRawDataImpl )

#endif /* defined( __cplusplus ) && !defined( SWIG ) */

#endif /* FrameCPP_UNIVERSAL__FRIMPL__FrRawDataData_HH */
