Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

asterism.cpp File Reference

#include <algorithm>
#include <config.h>
#include <celutil/util.h>
#include <celutil/debug.h>
#include "parser.h"
#include "asterism.h"

Include dependency graph for asterism.cpp:

Go to the source code of this file.

Functions

AsterismListReadAsterismList (istream &in, const StarDatabase &stardb)


Function Documentation

AsterismList* ReadAsterismList istream &  in,
const StarDatabase stardb
 

Definition at line 57 of file asterism.cpp.

References Asterism::addChain(), DPRINTF, Value::getArray(), Star::getPosition(), Tokenizer::getStringValue(), Tokenizer::getTokenType(), Value::getType(), Tokenizer::nextToken(), and Parser::readValue().

Referenced by CelestiaCore::initSimulation().

00058 {
00059     AsterismList* asterisms = new AsterismList();
00060     Tokenizer tokenizer(&in);
00061     Parser parser(&tokenizer);
00062 
00063     while (tokenizer.nextToken() != Tokenizer::TokenEnd)
00064     {
00065         if (tokenizer.getTokenType() != Tokenizer::TokenString)
00066         {
00067             DPRINTF(0, "Error parsing asterism file.\n");
00068             for_each(asterisms->begin(), asterisms->end(), deleteFunc<Asterism*>());
00069             delete asterisms;
00070             return NULL;
00071         }
00072 
00073         string name = tokenizer.getStringValue();
00074         Asterism* ast = new Asterism(name);
00075 
00076         Value* chainsValue = parser.readValue();
00077         if (chainsValue == NULL || chainsValue->getType() != Value::ArrayType)
00078         {
00079             DPRINTF(0, "Error parsing asterism %s\n", name.c_str());
00080             for_each(asterisms->begin(), asterisms->end(), deleteFunc<Asterism*>());
00081             delete asterisms;
00082             return NULL;
00083         }
00084 
00085         Array* chains = chainsValue->getArray();
00086 
00087         for (int i = 0; i < (int) chains->size(); i++)
00088         {
00089             if ((*chains)[i]->getType() == Value::ArrayType)
00090             {
00091                 Array* a = (*chains)[i]->getArray();
00092                 Asterism::Chain* chain = new Asterism::Chain();
00093                 for (Array::const_iterator iter = a->begin(); iter != a->end(); iter++)
00094                 {
00095                     if ((*iter)->getType() == Value::StringType)
00096                     {
00097                         Star* star = stardb.find((*iter)->getString());
00098                         if (star != NULL)
00099                             chain->insert(chain->end(), star->getPosition());
00100                     }
00101                 }
00102                 
00103                 ast->addChain(*chain);
00104             }
00105         }
00106 
00107         asterisms->insert(asterisms->end(), ast);
00108 
00109         delete chainsValue;
00110     }
00111 
00112     return asterisms;
00113 }


Generated on Sat Jan 14 22:30:34 2006 for Celestia by  doxygen 1.4.1