Object.cc
musicmud-2.1.6/src/Object.cc · 2.1 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD Daemon, version 1.0
* Copyright (C) 1998-2003 Abigail Brady
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "Object.h"
inline void strfree(const char *p) {
free((void*)p);
}
void base::set(const char *key, int val)
{
unset(key);
ints[key] = val;
}
void base::set(const char *key, const char *val)
{
unset(key);
if (val) {
strs[key] = val;
}
}
const char *base::get(const char *key) const
{
cstrit t = strs.find(key);
if (t==strs.end())
return 0;
return t->second.c_str();
}
int base::get_int(const char *key, int def) const
{
cintit t = ints.find(key);
if (t==ints.end())
return def;
return t->second;
}
void base::unset(const char *key)
{
intit t = ints.find(key);
if (t!=ints.end()) {
ints.erase(t);
}
strit t2 = strs.find(key);
if (t2!=strs.end()) {
strs.erase(t2);
}
}
#define get_string(a) get(a)
int objects;
Object::Object(const char *_id) {
id = _id?strdup(_id):0;
nuke_me = 0;
#ifdef CONFIG_TEMPLATES
templ = 0;
#endif
quit = 0;
objects++;
refcount = 0;
}
Object::~Object() {
if(id)
strfree(id);
objects--;
}
void Object::set(const char *key, const char *val)
{
if (!strcmp(key, "id")) {
strfree(id);
id = val?strdup(val):0;
return;
}
base::set(key, val);
}
const char *Object::get(const char *key) const
{
if (!strcmp(key, "id"))
return id;
return base::get(key);
}
common::~common() {
}