February 1999
- client images Chris Gray
- Question on c++ switch optimization, and parsers in general. Ben Greear
- Question on c++ switch optimization, and parsers in general. Adam Wiggins
- Question on c++ switch optimization, and parsers in general. Ola Fosheim Grøstad
- Question on c++ switch optimization, and parsers in general. Chris Gray
- Question on c++ switch optimization, and parsers in general. Chris Gray
- Question on c++ switch optimization, and parsers in general. T. Alexander Popiel
- Question on c++ switch optimization, and parsers in general. Ola Fosheim Grøstad
- Question on c++ switch optimization, and parsers in general. Richard Woolcock
- Question on c++ switch optimization, and parsers in general. Marc Hernandez
- Question on c++ switch optimization, and parsers i Chris Gray
- Question on c++ switch optimization, and parsers i Jon A. Lambert
- Question on c++ switch optimization, and parsers i Chris Gray
- optimizing code diablo@best.com
- optimizing code Hans-Henrik Staerfeldt
- optimizing code Chris Gray
- code profiling Chris Gray
- World-file parsing and RTTI? The Arrow
- World-file parsing and RTTI? Mark Gritter
Joachim Pileborg writes:
>
> For my MUD, I have a simple yet pretty good (IMHO :) format for world-files.
> A file contains one or more objects (monsters, locations, etc.), and each
> object have a list of properties (key-value pairs). Right now I have a
> simple lexer in flex that search for certain keywords like "monster",
> "location", "item". When the parser finds such a keyword I create a new
> instance of that specific C++ class.
I'm not clear here on what the strategy is: you create an instance of
the C++ class with the same name? What does your table contain as the
"value" associated with a particular keyword?
> My goal for the parser is to make it as flexible as possible, all anyone
> using my code should have to do, is to add a line to a table.
> Now comes the question: What is the best way to do this? I have though
> about using RTTI, but to my knowledge there exists no platform/compiler
> independant system. I could limit the MUD to just be compileable with gcc
> or egcs, but I don't like limiting myself in any way.
> Discussion?
>
RTTI is part of the standard. Anything in ISO C++ that g++/egcs can handle
should be available in commercial compilers by now. (I hope.)
The "standard" solution to adding this flexiblity is to use factory classes
rather than trying to use some language feature to create the right type.
I'll sketch an example below of how I've done this on other projects.
(Not MUDs... yet.)
class EntityFactory {
public:
/* Load an entity from the file. Subclasses of EntityFactory
* handle different types.
*/
virtual Ptr<Entity> loadEntity(istream &in) = 0;
};
/* Depending on how your parser works, istream &in might be replaced
* by list<KeywordValuePairs> or something else appropriate for creating
* the entity.
*
* "WorldContext" specifies where the new entity goes in some way.
*/
void Parser::handleKeyword(string keyword, istream &in, WorldContext &world) {
Ptr<EntityFactory> factory = keywordTable->lookup(keyword);
Ptr<Entity> newEntity = factory->loadEntity(in):
world.addEntity(newEntity);
}
class MonsterFactory : public EntityFactory {
public:
virtual Ptr<Entity> loadEntity(istream &in) { ... }
};
class WeaponFactory : public EntityFactory {
public:
virtual Ptr<Entity> loadEntity(istream &in) { ... }
};
void init(void) {
keywordTable->add("monster", new MonsterFactory());
keywordTable->add("weapon", new WeaponFactory());
...
}
This allows new types to be added by creating the new factory and putting
it in the keywordTable so that the parser can find it. RTTI might be used
by "WorldContext" to determine what sort of thing got returned from the
parser, but something like:
if ((foo = dynamic_cast<Weapon *>(newEntity))) { ... }
else if ((bar = dynamic_cast<Player *>(newEntity))) { ... }
...
should probably be avoided in favor of double-dispatch if there are going to
be a lot of cases.
(Currently, I'm using something like this to parse DNS packets: each type
of resource record has its own factory which knows how to interpret the
contents and return a class of the right type. Any operations are done
using double-dispatch on all the RRs in a Message object.)
Mark Gritter
mgritter@cs.stanford.edu
- World-file parsing and RTTI? Mark Gritter
- pet peeves diablo@best.com
- pet peeves diablo@best.com
- pet peeves Caliban Tiresias Darklock
- pet peeves Marc Bowden
- pet peeves Richard Woolcock
- pet peeves Koster, Raph
- pet peeves diablo@best.com
- pet peeves Caliban Tiresias Darklock
- pet peeves Kristen Koster
- pet peeves Caliban Tiresias Darklock
- pet peeves Adam Wiggins
- pet peeves Wes Connell
- pet peeves J C Lawrence
- pet peeves Matthew Mihaly
- pet peeves Ling
- pet peeves Ola Fosheim Grøstad
- pet peeves Matthew Mihaly
- pet peeves Ola Fosheim Grøstad
- pet peeves Matthew Mihaly
- pet peeves David Bennett
- pet peeves Robert Woods
- pet peeves Wes Connell
- pet peeves Travis S. Casey
- pet peeves Matthew Mihaly
- pet peeves Neerenberg, AaronX
- pet peeves greg
- pet peeves Richard Woolcock
- pet peeves J C Lawrence
- pet peeves Martin Keegan
- pet peeves Ola Fosheim Grøstad
- pet peeves J C Lawrence
- pet peeves diablo@best.com
- pet peeves Brandon A Downey
- pet peeves diablo@best.com
- pet peeves Darren Henderson
- pet peeves diablo@best.com
- pet peeves Darren Henderson
- pet peeves Steve Houchard
- pet peeves diablo@best.com
- pet peeves Darren Henderson
- pet peeves diablo@best.com
- pet peeves Steve Houchard
- pet peeves diablo@best.com
- pet peeves Richard Woolcock
- pet peeves diablo@best.com
- pet peeves Richard Woolcock
- pet peeves Apocalypse
- pet peeves Caliban Tiresias Darklock
- pet peeves diablo@best.com
- pet peeves Adam Wiggins
- pet peeves diablo@best.com
- pet peeves Adam Wiggins
- pet peeves diablo@best.com
- pet peeves Mik Clarke
- pet peeves Caliban Tiresias Darklock
- pet peeves Travis S. Casey
- pet peeves Caliban Tiresias Darklock
- pet peeves Benjamin D. Wiechel
- pet peeves Marc Bowden
- pet peeves Matthew Mihaly
- pet peeves Mik Clarke
- pet peeves Benjamin D. Wiechel
- pet peeves Matthew Mihaly
- pet peeves Caliban Tiresias Darklock
- pet peeves Marc Bowden
- pet peeves Matthew Mihaly
- pet peeves David Bennett
- pet peeves David Bennett
- pet peeves Petri Virkkula
- pet peeves J C Lawrence
- Horror Themed Muds [was CthulhuMud Driver 6] Christopher Allen
- Horror Themed Muds [was CthulhuMud Driver 6] Caliban Tiresias Darklock
- Horror Themed Muds [was CthulhuMud Driver 6] Mik Clarke
- CthulhuMud Driver 6 Mik Clarke
- CthulhuMud Driver 6 J C Lawrence
- Mathengine Ling
- Mathengine Apocalypse
- Website update Koster, Raph
- Influential muds Koster, Raph
- Influential muds Dan Shiovitz
- Influential muds Adam Wiggins
- Influential muds Sunny Gulati
- Influential muds diablo@best.com
- Influential muds Juha Lindfors
- Influential muds Brandon J. Rickman
- Influential muds Caliban Tiresias Darklock
- Influential muds Andy Cink
- Influential muds J C Lawrence
- Influential muds Dr. Cat
- Influential muds Jay Carlson
- Influential muds Mik Clarke
- Influential muds Richard Woolcock
- Influential muds Koster, Raph
- Influential muds Mik Clarke
- Influential muds Ola Fosheim Grøstad
- Influential muds Dan Root
- Influential muds Benjamin D. Wiechel
- State of the art? Andy Cink
- State of the art? diablo@best.com
- State of the art? Caliban Tiresias Darklock
- State of the art? ##Make Nylander
- State of the art? diablo@best.com
- State of the art? Martin Keegan
- State of the art? David Bennett
- State of the art? Martin Keegan
- State of the art? Andy Cink
- State of the art? J C Lawrence
- State of the art? David Bennett
- State of the art? Matthew Mihaly
- State of the art? Caliban Tiresias Darklock
- State of the art? Matthew Mihaly
- State of the art? Ola Fosheim Grøstad
- State of the art? Ola Fosheim Grøstad
- State of the art? J C Lawrence
- State of the art? Matthew Mihaly
- State of the art? Mik Clarke
- State of the art? J C Lawrence
- The Terrorist Class Ola Fosheim Grøstad
- The Terrorist Class Mik Clarke
- Welcome To "MUD-Dev"! mud-dev-admin@kanga.nu
- IMPORTANT ADMIN: New list setup requires your attention J C Lawrence
- ADMIN: URL change J C Lawrence
- PermaDeath (was pet peeves) Marc Hernandez
- ScryMUD 1.8.7 released. Ben Greear
- PermaDeath Sayeed
- PermaDeath Ola Fosheim Grøstad
- PermaDeath Sayeed
- roleplaying and immersion (was: PermaDeath) Ola Fosheim Grøstad
- Roleplaying and Immersion (was: PermaDeath) Sayeed
- Roleplaying and Immersion (was: PermaDeath) Adam Wiggins
- Roleplaying and Immersion (was: PermaDeath) J C Lawrence
- Roleplaying and Immersion (was: PermaDeath) Ola Fosheim Grøstad
- WEB: VR-stuff Ola Fosheim Grøstad
- WEB: VR-stuff J C Lawrence
- WEB: VR-stuff Mik Clarke
- WEB: VR-stuff Marian Griffith
- WEB: VR-stuff J C Lawrence
- ADMIN: The list archives are now online and fully searchable J C Lawrence
- Theories was pet peeves Wes Connell