209 lines
5.6 KiB
C++
209 lines
5.6 KiB
C++
![]() |
/*
|
||
|
* This file is part of the Colobot: Gold Edition source code
|
||
|
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
* See the GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see http://gnu.org/licenses
|
||
|
*/
|
||
|
|
||
|
// Modules inlcude
|
||
|
#include "CBotTypResult.h"
|
||
|
|
||
|
#include "CBotEnums.h"
|
||
|
|
||
|
#include "CBotClass.h"
|
||
|
|
||
|
// Local include
|
||
|
|
||
|
// Global include
|
||
|
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////
|
||
|
// management of results types
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult(int type)
|
||
|
{
|
||
|
m_type = type;
|
||
|
m_pNext = nullptr;
|
||
|
m_pClass = nullptr;
|
||
|
m_limite = -1;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult(int type, const char* name)
|
||
|
{
|
||
|
m_type = type;
|
||
|
m_pNext = nullptr;
|
||
|
m_pClass = nullptr;
|
||
|
m_limite = -1;
|
||
|
|
||
|
if ( type == CBotTypPointer ||
|
||
|
type == CBotTypClass ||
|
||
|
type == CBotTypIntrinsic )
|
||
|
{
|
||
|
m_pClass = CBotClass::Find(name);
|
||
|
if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult(int type, CBotClass* pClass)
|
||
|
{
|
||
|
m_type = type;
|
||
|
m_pNext = nullptr;
|
||
|
m_pClass = pClass;
|
||
|
m_limite = -1;
|
||
|
|
||
|
if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult(int type, CBotTypResult elem)
|
||
|
{
|
||
|
m_type = type;
|
||
|
m_pNext = nullptr;
|
||
|
m_pClass = nullptr;
|
||
|
m_limite = -1;
|
||
|
|
||
|
if ( type == CBotTypArrayPointer ||
|
||
|
type == CBotTypArrayBody )
|
||
|
m_pNext = new CBotTypResult( elem );
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult(const CBotTypResult& typ)
|
||
|
{
|
||
|
m_type = typ.m_type;
|
||
|
m_pClass = typ.m_pClass;
|
||
|
m_pNext = nullptr;
|
||
|
m_limite = typ.m_limite;
|
||
|
|
||
|
if ( typ.m_pNext )
|
||
|
m_pNext = new CBotTypResult( *typ.m_pNext );
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::CBotTypResult()
|
||
|
{
|
||
|
m_type = 0;
|
||
|
m_limite = -1;
|
||
|
m_pNext = nullptr;
|
||
|
m_pClass = nullptr;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult::~CBotTypResult()
|
||
|
{
|
||
|
delete m_pNext;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
int CBotTypResult::GetType(int mode) const
|
||
|
{
|
||
|
#ifdef _DEBUG
|
||
|
if ( m_type == CBotTypPointer ||
|
||
|
m_type == CBotTypClass ||
|
||
|
m_type == CBotTypIntrinsic )
|
||
|
|
||
|
if ( m_pClass == nullptr ) assert(0);
|
||
|
|
||
|
|
||
|
if ( m_type == CBotTypArrayPointer )
|
||
|
if ( m_pNext == nullptr ) assert(0);
|
||
|
#endif
|
||
|
if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer;
|
||
|
return m_type;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
void CBotTypResult::SetType(int n)
|
||
|
{
|
||
|
m_type = n;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotClass* CBotTypResult::GetClass() const
|
||
|
{
|
||
|
return m_pClass;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult& CBotTypResult::GetTypElem() const
|
||
|
{
|
||
|
return *m_pNext;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
int CBotTypResult::GetLimite() const
|
||
|
{
|
||
|
return m_limite;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
void CBotTypResult::SetLimite(int n)
|
||
|
{
|
||
|
m_limite = n;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
void CBotTypResult::SetArray( int* max )
|
||
|
{
|
||
|
m_limite = *max;
|
||
|
if (m_limite < 1) m_limite = -1;
|
||
|
|
||
|
if ( m_pNext != nullptr ) // last dimension?
|
||
|
{
|
||
|
m_pNext->SetArray( max+1 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
bool CBotTypResult::Compare(const CBotTypResult& typ) const
|
||
|
{
|
||
|
if ( m_type != typ.m_type ) return false;
|
||
|
|
||
|
if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext);
|
||
|
|
||
|
if ( m_type == CBotTypPointer ||
|
||
|
m_type == CBotTypClass ||
|
||
|
m_type == CBotTypIntrinsic )
|
||
|
{
|
||
|
return m_pClass == typ.m_pClass;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
bool CBotTypResult::Eq(int type) const
|
||
|
{
|
||
|
return m_type == type;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src)
|
||
|
{
|
||
|
m_type = src.m_type;
|
||
|
m_limite = src.m_limite;
|
||
|
m_pClass = src.m_pClass;
|
||
|
m_pNext = nullptr;
|
||
|
if ( src.m_pNext != nullptr )
|
||
|
{
|
||
|
m_pNext = new CBotTypResult(*src.m_pNext);
|
||
|
}
|
||
|
return *this;
|
||
|
}
|