2019-10-29 13:15:13 +00:00
# include "stdafx.h"
# include "Form.h"
2020-03-05 15:30:50 +00:00
namespace FSecure : : C3 : : Linter
2019-10-29 13:15:13 +00:00
{
2019-11-13 14:39:29 +00:00
Form : : Form ( json argumentForm ) :
m_ArgumentsForm ( std : : move ( argumentForm ) )
2019-10-29 13:15:13 +00:00
{
2019-11-13 14:39:29 +00:00
for ( auto & arg : m_ArgumentsForm )
2019-10-29 13:15:13 +00:00
{
2019-11-13 14:39:29 +00:00
if ( arg . is_array ( ) )
2019-10-29 13:15:13 +00:00
{
2019-11-13 14:39:29 +00:00
for ( auto & a : arg )
{
m_Elements . emplace_back ( MakeFormElement ( a ) ) ;
}
2019-10-29 13:15:13 +00:00
}
2019-11-13 14:39:29 +00:00
else
2019-10-31 12:11:49 +00:00
{
2019-11-13 14:39:29 +00:00
m_Elements . emplace_back ( MakeFormElement ( arg ) ) ;
2019-10-31 12:11:49 +00:00
}
2019-10-29 13:15:13 +00:00
}
}
2019-10-29 13:18:56 +00:00
2019-11-13 14:39:29 +00:00
Form : : Form ( Form const & other ) noexcept :
Form ( other . m_ArgumentsForm )
{
}
2019-11-25 11:22:41 +00:00
Form & Form : : operator = ( Form other ) noexcept
2019-11-13 14:39:29 +00:00
{
2019-11-25 11:22:41 +00:00
std : : swap ( m_ArgumentsForm , other . m_ArgumentsForm ) ;
std : : swap ( m_Elements , other . m_Elements ) ;
2019-11-13 14:39:29 +00:00
return * this ;
}
2019-11-18 12:57:56 +00:00
json Form : : Fill ( StringVector const & input )
2019-11-13 14:39:29 +00:00
{
if ( input . size ( ) < m_Elements . size ( ) )
throw std : : runtime_error ( " Not enough arguments given to fill out form [required = " + std : : to_string ( m_Elements . size ( ) ) + " , given = " + std : : to_string ( input . size ( ) ) + " ] " ) ;
// TODO log "Too many arguments, ignoring some of them"
// if (input.size() > m_Elemets.size())
auto inputIt = begin ( input ) ;
std : : for_each ( begin ( m_Elements ) , end ( m_Elements ) , [ & inputIt ] ( auto & element ) { element - > ValidateAndSet ( * inputIt + + ) ; } ) ;
return m_ArgumentsForm ;
}
2019-11-07 16:21:44 +00:00
StringVector Form : : GetComplementaryArgs ( StringVector input )
2019-10-29 13:18:56 +00:00
{
2019-11-07 16:21:44 +00:00
size_t currentOffset = 0 ;
for ( auto const & arg : m_ArgumentsForm )
2019-10-29 13:18:56 +00:00
{
if ( arg . is_array ( ) )
{
2019-11-07 16:21:44 +00:00
auto size = arg . size ( ) ;
auto first = begin ( input ) + currentOffset ;
std : : rotate ( first , first + size - 1 , first + size ) ;
currentOffset + = size ;
2019-10-29 13:18:56 +00:00
}
else
{
2019-11-07 16:21:44 +00:00
+ + currentOffset ;
2019-10-29 13:18:56 +00:00
}
}
2019-11-07 16:21:44 +00:00
return input ;
2019-10-29 13:18:56 +00:00
}
2019-10-29 13:15:13 +00:00
}