From 04aba413306c0877e68f902e8273d0f967116f7a Mon Sep 17 00:00:00 2001 From: Chris Laurel Date: Thu, 6 Sep 2001 00:57:33 +0000 Subject: [PATCH] List of destinations for tour guide dialog. --- src/destination.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++ src/destination.h | 34 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/destination.cpp create mode 100644 src/destination.h diff --git a/src/destination.cpp b/src/destination.cpp new file mode 100644 index 000000000..e0f00c330 --- /dev/null +++ b/src/destination.cpp @@ -0,0 +1,79 @@ +// destination.cpp +// +// Copyright (C) 2001, Chris Laurel +// +// 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. + +#include +#include "celestia.h" +#include "util.h" +#include "parser.h" +#include "destination.h" + +using namespace std; + + +Destination::Destination() : + name(""), + target(""), + distance(0.0), + description("") +{ +} + + +DestinationList* ReadDestinationList(istream& in) +{ + Tokenizer tokenizer(&in); + Parser parser(&tokenizer); + DestinationList* destinations = new DestinationList(); + + cout << "ReadDestinationList\n"; + + while (tokenizer.nextToken() != Tokenizer::TokenEnd) + { + if (tokenizer.getTokenType() != Tokenizer::TokenBeginGroup) + { + DPRINTF("Error parsing destinations file.\n"); + for_each(destinations->begin(), destinations->end(), deleteFunc()); + delete destinations; + return NULL; + } + tokenizer.pushBack(); + + Value* destValue = parser.readValue(); + if (destValue == NULL || destValue->getType() != Value::HashType) + { + DPRINTF("Error parsing destination.\n"); + for_each(destinations->begin(), destinations->end(), deleteFunc()); + delete destinations; + if (destValue != NULL) + delete destValue; + return NULL; + } + + Hash* destParams = destValue->getHash(); + Destination* dest = new Destination(); + + if (!destParams->getString("Name", dest->name)) + { + DPRINTF("Skipping unnamed destination\n"); + delete dest; + } + else + { + cout << "Reading destination: " << dest->name << '\n'; + destParams->getString("Target", dest->target); + destParams->getString("Description", dest->description); + destParams->getNumber("Distance", dest->distance); + destinations->insert(destinations->end(), dest); + } + + delete destValue; + } + + return destinations; +} diff --git a/src/destination.h b/src/destination.h new file mode 100644 index 000000000..4133f85c6 --- /dev/null +++ b/src/destination.h @@ -0,0 +1,34 @@ +// destination.h +// +// Copyright (C) 2001, Chris Laurel +// +// 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. + +#ifndef _DESTINATION_H_ +#define _DESTINATION_H_ + +#include +#include +#include + + +class Destination +{ + public: + Destination(); + + public: + std::string name; + std::string target; + double distance; + std::string description; +}; + +typedef std::vector DestinationList; + +DestinationList* ReadDestinationList(std::istream&); + +#endif // _DESTINATION_H_