⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portion.cc

📁 Gambit 是一个游戏库理论软件
💻 CC
📖 第 1 页 / 共 4 页
字号:
//// $Source: /home/gambit/CVS/gambit/sources/gcl/portion.cc,v $// $Date: 2002/08/27 18:57:19 $// $Revision: 1.4 $//// DESCRIPTION:// Implementation of GCL data types//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// 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 2 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, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//#include "base/base.h"#include "portion.h"#include "gsmhash.h"#include "gsm.h"#include "game/nfg.h"#include "game/efg.h"//-----------// Portion//-----------gNumber Portion::_WriteWidth = 0;gNumber Portion::_WritePrecis = 6;gTriState Portion::_WriteExpmode = triFALSE;gTriState Portion::_WriteQuoted = triTRUE;gTriState Portion::_WriteListBraces = triTRUE;gTriState Portion::_WriteListCommas = triTRUE;gNumber Portion::_WriteListLF = 0;gNumber Portion::_WriteListIndent = 2;gTriState Portion::_WriteSolutionInfo = triFALSE;gTriState Portion::_WriteSolutionLabels = triTRUE;void Portion::_SetWriteWidth(long x){ _WriteWidth = x; }void Portion::_SetWritePrecis(long x){ _WritePrecis = x; }void Portion::_SetWriteExpmode(bool x){ _WriteExpmode = (x) ? triTRUE : triFALSE; }void Portion::_SetWriteQuoted(bool x){ _WriteQuoted = (x) ? triTRUE : triFALSE; }void Portion::_SetWriteListBraces(bool x){ _WriteListBraces = (x) ? triTRUE : triFALSE; }void Portion::_SetWriteListCommas(bool x){ _WriteListCommas = (x) ? triTRUE : triFALSE; }void Portion::_SetWriteListLF(long x){ _WriteListLF = x; }void Portion::_SetWriteListIndent(long x){ _WriteListIndent = x; }void Portion::_SetWriteSolutionInfo(bool x){ _WriteSolutionInfo = (x) ? triTRUE : triFALSE; }void Portion::_SetWriteSolutionLabels(bool x){ _WriteSolutionLabels = (x) ? triTRUE : triFALSE; }void Portion::Output(gOutput& s) const{  s.SetWidth((int) _WriteWidth);  s.SetPrec((int) _WritePrecis);  if(_WriteExpmode)    s.SetExpMode();  else    s.SetFloatMode();}#ifdef MEMCHECKint Portion::_NumObj = 0;#endifPortion::Portion(void)  : _Original(0), _Game(0), _GameIsEfg(false){#ifdef MEMCHECK  _NumObj++;  //  printf("--- Portion Ctor, count: %d\n", _NumObj);#endif}Portion::~Portion(){   if (_Game && _GameIsEfg) {    SetGame((efgGame *) 0);  }  else if (_Game) {    SetGame((Nfg *) 0);  }#ifdef MEMCHECK  _NumObj--;  //printf("--- Portion Dtor, count: %d\n", _NumObj);#endif}void Portion::SetOriginal(const Portion* p){   _Original = (Portion*) p;}Portion *Portion::Original(void) const{   if (!IsReference()) {    return (Portion *) this;  }  else  {    return _Original;   }}void *Portion::Game(void) const{  return _Game;}bool Portion::GameIsEfg(void) const{  switch (Spec().Type)  {  case porNFG:    return false;  case porEFG:    return true;  default:    return _GameIsEfg;  }}void Portion::SetGame(const Nfg *game){  if (game != _Game)  {    if (_Game)  {       GSM::GameRefCount(_Game)--;#ifdef MEMCHECK      gout<<"Game "<<_Game<<" ref count-: "<< _gsm->GameRefCount(_Game) <<'\n';#endif      if (GSM::GameRefCount(_Game) == 0)         delete (Nfg *) _Game;    }             _Game = (void *) game;    _GameIsEfg = false;          if (_Game)  {      GSM::GameRefCount(_Game)++;#ifdef MEMCHECK      gout<<"Game "<<_Game<<" ref count+: "<<_gsm->GameRefCount(_Game)<<'\n';#endif    }  }}void Portion::SetGame(const efgGame *game){  if (game != _Game)  {    if (_Game)  {      GSM::GameRefCount(_Game)--;#ifdef MEMCHECK      gout<<"Game "<<_Game<<" ref count-: "<< _gsm->GameRefCount(_Game) <<'\n';#endif      if (GSM::GameRefCount(_Game) == 0)   	delete (efgGame *) _Game;    }        _Game = (void *) game;    _GameIsEfg = true;        if (_Game)  {      GSM::GameRefCount(_Game)++;#ifdef MEMCHECK      gout<<"Game "<<_Game<<" ref count+: "<<_gsm->GameRefCount(_Game)<<'\n';#endif    }  }}//--------// Null//--------gPool NullPortion::pool(sizeof(NullPortion));NullPortion::NullPortion(const unsigned long datatype): _DataType(datatype){ }NullPortion::~NullPortion(){ }unsigned long NullPortion::DataType(void) const{ return _DataType; }PortionSpec NullPortion::Spec(void) const{ return PortionSpec(porNULL, 0, true); }void NullPortion::Output(gOutput& s) const{  Portion::Output(s);  s << OutputString();}gText NullPortion::OutputString(void) const{  return (gText) "Null(" + PortionSpecToText(_DataType) + ")";}Portion* NullPortion::ValCopy(void) const{ return new NullPortion(_DataType); }Portion* NullPortion::RefCopy(void) const{ return new NullPortion(_DataType); }bool NullPortion::IsReference(void) const{ return false; }//-------------// Reference//-------------gPool ReferencePortion::pool(sizeof(ReferencePortion));ReferencePortion::ReferencePortion(const gText& value): _Value(value){ }ReferencePortion::~ReferencePortion(){ }gText ReferencePortion::Value(void){ return _Value; }PortionSpec ReferencePortion::Spec(void) const{ return PortionSpec(porREFERENCE); }void ReferencePortion::Output(gOutput& s) const{   Portion::Output(s);  s << OutputString();}gText ReferencePortion::OutputString(void) const{  return (gText) "(Reference) \"" + _Value + "\""; }Portion* ReferencePortion::ValCopy(void) const{ return new ReferencePortion(_Value); }Portion* ReferencePortion::RefCopy(void) const{ return new ReferencePortion(_Value); }bool ReferencePortion::IsReference(void) const{ return false; }//-------------// Precision//-------------gPool PrecisionPortion::pool(sizeof(PrecisionPortion));PrecisionPortion::PrecisionPortion(gPrecision value)  : _Value(new gPrecision(value)), _ref(false){ }PrecisionPortion::PrecisionPortion(gPrecision &value, bool ref)  : _Value(&value), _ref(ref){ }PrecisionPortion::~PrecisionPortion(){  if (!_ref)    delete _Value;}gPrecision PrecisionPortion::Value(void) const{ return *_Value; }void PrecisionPortion::SetValue(gPrecision p){ *_Value = p; }PortionSpec PrecisionPortion::Spec(void) const{ return PortionSpec(porPRECISION); }void PrecisionPortion::Output(gOutput& s) const{  Portion::Output(s);  s << ((*_Value == precDOUBLE) ? "Float" : "Rational");}gText PrecisionPortion::OutputString(void) const{  return (*_Value == precDOUBLE) ? "Float" : "Rational";}Portion* PrecisionPortion::ValCopy(void) const{ return new PrecisionPortion(*_Value); }Portion* PrecisionPortion::RefCopy(void) const{   Portion* p = new PrecisionPortion(*_Value, true);  p->SetOriginal(Original());  return p;}bool PrecisionPortion::IsReference(void) const{ return _ref; }//---------// Number//---------gPool NumberPortion::pool(sizeof(NumberPortion));NumberPortion::NumberPortion(const gNumber &value)  : _Value(new gNumber(value)), _ref(false){ }NumberPortion::NumberPortion(gNumber &value, bool ref)  : _Value(&value), _ref(ref){ }NumberPortion::~NumberPortion(){  if (!_ref)    delete _Value;}const gNumber &NumberPortion::Value(void) const{ return *_Value; }void NumberPortion::SetValue(const gNumber &n){ *_Value = n; }PortionSpec NumberPortion::Spec(void) const{ return PortionSpec(porNUMBER); }void NumberPortion::Output(gOutput& s) const{  Portion::Output(s);  s << *_Value; }gText NumberPortion::OutputString(void) const{  return ToText(*_Value);}Portion* NumberPortion::ValCopy(void) const{ return new NumberPortion(*_Value); }Portion* NumberPortion::RefCopy(void) const{   Portion* p = new NumberPortion(*_Value, true);   p->SetOriginal(Original());  return p;}bool NumberPortion::IsReference(void) const{ return _ref; }//--------// Text//--------gPool TextPortion::pool(sizeof(TextPortion));TextPortion::TextPortion(const gText &value)  : _Value(new gText(value)), _ref(false){ }TextPortion::TextPortion(gText &value, bool ref)  : _Value(&value), _ref(ref){ }TextPortion::~TextPortion(){  if (!_ref)    delete _Value;}const gText &TextPortion::Value(void) const{ return *_Value; }void TextPortion::SetValue(const gText &v){ *_Value = v; }PortionSpec TextPortion::Spec(void) const{ return PortionSpec(porTEXT); }void TextPortion::Output(gOutput& s) const{   Portion::Output(s);  s << OutputString();}gText TextPortion::OutputString(void) const{  gText text = *_Value;  if(_WriteQuoted)     text = (gText) '\"' + text + "\"";  return text;}Portion* TextPortion::ValCopy(void) const{ return new TextPortion(*_Value); }Portion* TextPortion::RefCopy(void) const{   Portion* p = new TextPortion(*_Value, true);   p->SetOriginal(Original());  return p;}bool TextPortion::IsReference(void) const{ return _ref; }//--------// Bool//--------gPool BoolPortion::pool(sizeof(BoolPortion));BoolPortion::BoolPortion(bool value)  : _Value(new gTriState((value) ? triTRUE : triFALSE)), _ref(false){ }BoolPortion::BoolPortion(gTriState value)  : _Value(new gTriState(value)), _ref(false){ }BoolPortion::BoolPortion(gTriState &value, bool ref)  : _Value(&value), _ref(ref){ }BoolPortion::~BoolPortion(){  if (!_ref)      delete _Value;}gTriState BoolPortion::Value(void) const{ return *_Value; }void BoolPortion::SetValue(gTriState v){ *_Value = v; }PortionSpec BoolPortion::Spec(void) const{ return PortionSpec(porBOOLEAN); }void BoolPortion::Output(gOutput& s) const{  Portion::Output(s);  s << OutputString();}gText BoolPortion::OutputString(void) const{  if (*_Value == triTRUE)    return "True";  else if (*_Value == triFALSE)    return "False";  else /* (*_Value == triMAYBE) */    return "Unknown";}Portion* BoolPortion::ValCopy(void) const{ return new BoolPortion(*_Value); }Portion* BoolPortion::RefCopy(void) const{   Portion* p = new BoolPortion(*_Value, true);  p->SetOriginal(Original());  return p;}bool BoolPortion::IsReference(void) const{ return _ref; }//-------------// EFOutcome//-------------gPool EfOutcomePortion::pool(sizeof(EfOutcomePortion));EfOutcomePortion::EfOutcomePortion(efgOutcome *p_value)  : m_value(new efgOutcome *(p_value)), m_ref(false){  SetGame((efgGame *) p_value->GetGame());}EfOutcomePortion::EfOutcomePortion(efgOutcome *&p_value, bool p_ref)  : m_value(&p_value), m_ref(p_ref){  if (!p_ref) {    SetGame((efgGame *) p_value->GetGame());  }}EfOutcomePortion::~EfOutcomePortion(){  if (!m_ref)  {    delete m_value;  }}efgOutcome *EfOutcomePortion::Value(void) const{ return *m_value; }void EfOutcomePortion::SetValue(efgOutcome *p_value){  if (m_ref) {    ((EfOutcomePortion *) Original())->SetValue(p_value);  }  else {    SetGame((efgGame *) p_value->GetGame());    *m_value = p_value;  }}PortionSpec EfOutcomePortion::Spec(void) const{  return porEFOUTCOME;}void EfOutcomePortion::Output(gOutput& s) const{  Portion::Output(s);    s << "(EFOutcome) ";  s << " \"" << (*m_value)->GetGame()->GetOutcomeName(*m_value) << "\"\n";}gText EfOutcomePortion::OutputString(void) const{  return "(EFOutcome)";}Portion* EfOutcomePortion::ValCopy(void) const{   return new EfOutcomePortion(*m_value);}Portion* EfOutcomePortion::RefCopy(void) const{   Portion* p = new EfOutcomePortion(*m_value, true);   p->SetOriginal(Original());  return p;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -