#include <algorithm>#include <celutil/debug.h>#include <celutil/util.h>#include <celengine/celestia.h>#include <celengine/astro.h>#include <celengine/parser.h>#include "destination.h"Include dependency graph for destination.cpp:

Go to the source code of this file.
Functions | |
| DestinationList * | ReadDestinationList (istream &in) |
|
|
Definition at line 30 of file destination.cpp. References astro::AUtoLightYears(), compareIgnoringCase(), Destination::description, Destination::distance, distanceUnits, DPRINTF, Value::getHash(), AssociativeArray::getNumber(), AssociativeArray::getString(), Tokenizer::getTokenType(), Value::getType(), astro::kilometersToLightYears(), Destination::name, Tokenizer::nextToken(), Tokenizer::pushBack(), Parser::readValue(), and Destination::target. Referenced by CelestiaCore::initSimulation(). 00031 {
00032 Tokenizer tokenizer(&in);
00033 Parser parser(&tokenizer);
00034 DestinationList* destinations = new DestinationList();
00035
00036 while (tokenizer.nextToken() != Tokenizer::TokenEnd)
00037 {
00038 if (tokenizer.getTokenType() != Tokenizer::TokenBeginGroup)
00039 {
00040 DPRINTF(0, "Error parsing destinations file.\n");
00041 for_each(destinations->begin(), destinations->end(), deleteFunc<Destination*>());
00042 delete destinations;
00043 return NULL;
00044 }
00045 tokenizer.pushBack();
00046
00047 Value* destValue = parser.readValue();
00048 if (destValue == NULL || destValue->getType() != Value::HashType)
00049 {
00050 DPRINTF(0, "Error parsing destination.\n");
00051 for_each(destinations->begin(), destinations->end(), deleteFunc<Destination*>());
00052 delete destinations;
00053 if (destValue != NULL)
00054 delete destValue;
00055 return NULL;
00056 }
00057
00058 Hash* destParams = destValue->getHash();
00059 Destination* dest = new Destination();
00060
00061 if (!destParams->getString("Name", dest->name))
00062 {
00063 DPRINTF(1, "Skipping unnamed destination\n");
00064 delete dest;
00065 }
00066 else
00067 {
00068 destParams->getString("Target", dest->target);
00069 destParams->getString("Description", dest->description);
00070 destParams->getNumber("Distance", dest->distance);
00071
00072 // Default unit of distance is the light year
00073 string distanceUnits;
00074 if (destParams->getString("DistanceUnits", distanceUnits))
00075 {
00076 if (!compareIgnoringCase(distanceUnits, "km"))
00077 dest->distance = astro::kilometersToLightYears(dest->distance);
00078 else if (!compareIgnoringCase(distanceUnits, "au"))
00079 dest->distance = astro::AUtoLightYears(dest->distance);
00080 }
00081
00082 destinations->insert(destinations->end(), dest);
00083 }
00084
00085 delete destValue;
00086 }
00087
00088 return destinations;
00089 }
|
1.4.1