Code Search for Developers
 
 
  

EntDict.cpp from palisma2d at Krugle


Show EntDict.cpp syntax highlighted

/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG                        *
*Copyright (C) 2006, Tony Sparks                                                     *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library 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                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "EntDict.h"


/*-------------------------------------------------------------------------------------
    Dictionary Entry
--------------------------------------------------------------------------------------*/

DictEntry::DictEntry()
{
    Clear();
}

void DictEntry::Clear()
{
    b_value = false;
    i_value = 0;
    f_value = 0.0f;
    s_value = "";
    m_name  = "";

    v_value.Set(0,0);
}


/*-------------------------------------------------------------------------------------
    Entity Dictionary 
--------------------------------------------------------------------------------------*/


EntDict::EntDict(void)
{

}

EntDict::~EntDict(void)
{
}


/** Put a property into the dictionary */
void EntDict::Put( const std::string &prop, const std::string &value )
{
    DictEntry ent;
    ent.s_value = value;

    m_vocab[ prop ] = ent;
}
void EntDict::Put( const std::string &prop, int value )
{
    DictEntry ent;
    ent.i_value = value;

    m_vocab[ prop ] = ent;
}
void EntDict::Put( const std::string &prop, float value )
{
    DictEntry ent;
    ent.f_value = value;

    m_vocab[ prop ] = ent;
}
void EntDict::Put( const std::string &prop, bool value )
{
    DictEntry ent;
    ent.b_value = value;

    m_vocab[ prop ] = ent;
}
void EntDict::Put( const std::string &prop, float v1, float v2 )
{
    DictEntry ent;
    ent.v_value = Vector2f(v1, v2 );

    m_vocab[ prop ] = ent;
}

/** Get a property */
int EntDict::GetInt( const std::string &prop )
{
    if ( Has( prop ) )
    {
        return m_vocab[prop].i_value;
    }
    return 0;
}

float EntDict::GetFloat( const std::string &prop )
{
    if ( Has( prop ) )
    {
        return m_vocab[prop].f_value;
    }
    return 0.0f;
}

Vector2f EntDict::GetVector2f( const std::string &prop )
{
    if ( Has( prop ) )
    {
        return m_vocab[prop].v_value;
    }
    return Vector2f();
}

std::string EntDict::GetStr( const std::string &prop )
{
    if ( Has( prop ) )
    {
        return m_vocab[prop].s_value;
    }
    return "";
}

/** Set a property */
void EntDict::SetStr( const std::string &prop, const std::string &value )
{
    if ( Has( prop ) )
    {
        m_vocab[prop].s_value = value;
    }
}
void EntDict::SetInt( const std::string &prop, int value )
{
    if ( Has( prop ) )
    {
        m_vocab[prop].i_value = value;
    }
}
void EntDict::SetFloat( const std::string &prop, float value )
{
    if ( Has( prop ) )
    {
        m_vocab[prop].f_value = value;
    }
}
void EntDict::SetBool( const std::string &prop, bool value )
{
    if ( Has( prop ) )
    {
        m_vocab[prop].b_value = value;
    }
}
void EntDict::SetVector( const std::string &prop, Vector2f value )
{
    if ( Has( prop ) )
    {
        m_vocab[prop].v_value = value;
    }
}

/** Clear all entries */
void EntDict::Clear()
{
    m_vocab.clear();
}

/** Test for property */
bool EntDict::Has( const std::string &prop )
{
    return ( m_vocab.find( prop ) != m_vocab.end() );
}







See more files for this project here

palisma2d

The University of Wisconsin-Parkside Developers Union first product. More info to come. Code name Palisma.

Project homepage: http://code.google.com/p/palisma2d/
Programming language(s): C,C++
License: gpl2

  EntDict.cpp
  EntDict.h
  Error.cpp
  Error.h
  MFile.cpp
  MFile.h
  Parser.cpp
  Parser.h
  QuadTree.cpp
  QuadTree.h
  ReadMe.txt
  StringUtil.cpp
  StringUtil.h
  Vector3f.cpp
  Vector3f.h
  color.h
  geom.h
  stdafx.cpp
  stdafx.h
  vector.h