// sattool - visual satellite tracking and prediction tool.
// Copyright 2000 Tom Rothamel <tom-idbg@onegeek.org>
//
// 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 "sattool.h"

// This file wound up being a mess of functions that I haven't found a
// better home for.

// Locks an object, memory-management wise.
void lock(Thing *t) {
	t->uses++;
}

// Unlock an object. If the uses count falls to zero, reclaim it.
void unlock(Thing *t) {
	t->uses--;
	if (t->uses) return;

	delete t;
}

// Initialize a new object, with the bogoinheritance set to default values.
Thing::Thing() {
	uses = 0;
	_sat = NULL;
	_object = NULL;
	_time = HUGE_VAL;
}

// Default, so virtual destruction works without having to declare
// destructors on every object.
Thing::~Thing() { }

// Constructor with Bogoinheritance.
Object::Object() {
	_object = this;
}

// Constructor with Bogoinheritance.
Sat::Sat() {
	_sat = this;
}

// Default write function.
void Thing::write(FILE *f, int d) {
	pad(f, d);
	printf("(thing)\n");
}

// A utility method on an object.
Position *Object::calc1(double t) {
        return calcpos(t, NULL);
}

/////////////////////// Bogoinheritance ////////////////////////////


Sat *getSat(Thing *t) {
	return t->_sat;
}

Object *getObject(Thing *t) {
	return t->_object;
}

Sgp4Sat *getSgp4Sat(Thing *t) {
	return dynamic_cast<Sgp4Sat *> (t->_sat);
}

Pass *getPass(Thing *t) {
	return dynamic_cast<Pass *> (t);
}

Encounter *getEncounter(Thing *t) {
	return dynamic_cast<Encounter *> (t);
}


//////////////////// Default Sat Implementation //////////////////////

int Sat::hasmag() {
	return 0;
}

double Sat::calcmag(Encounter *w) {
	return -HUGE_VAL;
}
