/*
* $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/iif/Interface/Ltcs/Iif/Side.cc 300 2017-11-21 09:45:39Z depa $
*
*/

/**
* @file
* @since 2017-01-17
* @author R. J. Mathar
*/

#include <Ltcs/Iif/Side.h>

/*!*********************
* Default ctor.
* Initialize the state as "no side" (of both)
* @param anysdx An enumerated constant indicating left, right, none or both.
* @since 2017-01-17
*/
Ltcs::IifSide::IifSide(enum IifSid anysdx)
: s(anysdx)
{
}

/*!*********************
* @brief construct from astring like "blabla right" or "bla both" or "sx" or "dx".
* @param fstation A string of the format found in the FOCAL_STATION property in lbcs.iif-dev.cfg
* @since 2017-01-17
* @since 2017-05-27 Interpret a "LIRCS" in the name as "both". Used for some drotator names.
*/
Ltcs::IifSide::IifSide(const std::string & fstation)
{
    if ( fstation.find("left") != std::string::npos || fstation.find("LEFT") != std::string::npos )
        s=SIDE_LEFT ;
    else if ( fstation.find("right") != std::string::npos || fstation.find("RIGHT") != std::string::npos )
        s=SIDE_RIGHT ;
    else if ( fstation.find("both") != std::string::npos || fstation.find("BOTH") != std::string::npos
              || fstation.find("lircs") != std::string::npos || fstation.find("LIRCS") != std::string::npos )
        s=SIDE_BOTH ;
    else if ( fstation.find("sx") != std::string::npos || fstation.find("SX") != std::string::npos )
        s=SIDE_LEFT ;
    else if ( fstation.find("dx") != std::string::npos || fstation.find("DX") != std::string::npos )
        s=SIDE_RIGHT ;
    else if ( fstation.find("0") != std::string::npos )
        s=SIDE_LEFT ;
    else if ( fstation.find("1") != std::string::npos )
        s=SIDE_RIGHT ;
    else
        /* this includes the case where the string none or NONE is in here
        */
        s=SIDE_NONE ;
}

/*!*********************
* @brief copy constructor
* @param oth The side to be duplicated
* @since 2017-01-17
*/
Ltcs::IifSide::IifSide(const Ltcs::IifSide & oth)
{
    s = oth.s ;
}


#if 0
/*!************************************
* @brief dtor.
* Does nothing (but what is done by the base class).
* @since 2017-01-17
*/
Ltcs::IifSide::~IifSide()
{
}
#endif

/*!************************************
* @brief Generate a string as used in the ICS initializations.
* @return the standard string representation "left", "right" or "both" or "none".
* @since 2017-01-17
*/
std::string Ltcs::IifSide::toString() const
{
    switch(s)
    {
    case SIDE_NONE :
        return std::string("none") ;
    case SIDE_LEFT :
        return std::string("left") ;
    case SIDE_RIGHT :
        return std::string("right") ;
    case SIDE_BOTH :
        return std::string("both") ;
    default :
        return std::string() ;
    }
}

/*!************************************
* @brief Generate a string as used in the file names.
* @return the standard string representation "sx" or "dx".
*   If this is not uniquely either SX or DX, an empty string is returned.
* @since 2017-01-17
*/
std::string Ltcs::IifSide::toStringCfg() const
{
    switch(s)
    {
    case SIDE_LEFT :
        return std::string("sx") ;
    case SIDE_RIGHT :
        return std::string("dx") ;
    default :
        return std::string() ;
    }
}

/*!************************************
* @brief Generate a index 0 or 1 suitable for the two indices of two proxies.
* @return 0 if SX, 1 if DX, -1 otherwise.
* @since 2017-01-17
*/
int Ltcs::IifSide::toIntIdx() const
{
    switch(s)
    {
    case SIDE_LEFT :
        return 0 ;
    case SIDE_RIGHT :
        return 1 ;
    default :
        return -1 ;
    }
}

/*!*******************************
* @brief Assignment operator.
*  Deep copy of this state.
* @since 2017-01-17
*/
Ltcs::IifSide & Ltcs::IifSide::operator=(const Ltcs::IifSide & oth)
{
    if ( this != & oth)
    {
        /* same procedure as for the copy ctor above.
        */
        s = oth.s ;
    }
    return *this ;
} /* Ltcs::IifSide::operator= */
