/*
   b_time_t.cpp   Generated by the Ballista(tm) Project data object compiler
   Copyright (C) 1998-2001  Carnegie Mellon University

   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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

   File generated Wednesday, May 23 at 02:56 AM EDT

TITLE
   b_time_t.cpp
*/

//--------------------------------------------------------------------

#include <errno.h>
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <stream.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "b_time_t.h"

//--------------------------------------------------------------------



#define MIDNIGHT_2000 (2000-1970)*365*24*60*60 
#define YEAR 365*24*60*60
#define DAY 24*60*60
#define HOUR 60*60
#define MINUTE 60
//--------------------------------------------------------------------

CLASSNAME::CLASSNAME()
{
  //DIAL DECLARATIONS HERE

  //generated

   strcpy(_b_time_tTYPENAME,CLASS_STRING);
strcpy(_b_time_tNOW,"b_time_t_NOW");
strcpy(_b_time_tTOMORROW,"b_time_t_TOMORROW");
strcpy(_b_time_tNEXTWEEK,"b_time_t_NEXTWEEK");
strcpy(_b_time_tNEXTMONTH,"b_time_t_NEXTMONTH");
strcpy(_b_time_tNEXTYEAR,"b_time_t_NEXTYEAR");
strcpy(_b_time_tNEXTDECADE,"b_time_t_NEXTDECADE");
strcpy(_b_time_tNEXTCENTURY,"b_time_t_NEXTCENTURY");
strcpy(_b_time_tNEXTMILLENIUM,"b_time_t_NEXTMILLENIUM");
strcpy(_b_time_tY2K,"b_time_t_Y2K");
strcpy(_b_time_tY2K_MINUS_ONE,"b_time_t_Y2K_MINUS_ONE");
strcpy(_b_time_tY2K_PLUS_ONE,"b_time_t_Y2K_PLUS_ONE");
}

//--------------------------------------------------------------------
b_param *b_time_t::b_time_tNOW()
{
   return &_b_time_tNOW;
}

b_param *b_time_t::b_time_tTOMORROW()
{
   return &_b_time_tTOMORROW;
}

b_param *b_time_t::b_time_tNEXTWEEK()
{
   return &_b_time_tNEXTWEEK;
}

b_param *b_time_t::b_time_tNEXTMONTH()
{
   return &_b_time_tNEXTMONTH;
}

b_param *b_time_t::b_time_tNEXTYEAR()
{
   return &_b_time_tNEXTYEAR;
}

b_param *b_time_t::b_time_tNEXTDECADE()
{
   return &_b_time_tNEXTDECADE;
}

b_param *b_time_t::b_time_tNEXTCENTURY()
{
   return &_b_time_tNEXTCENTURY;
}

b_param *b_time_t::b_time_tNEXTMILLENIUM()
{
   return &_b_time_tNEXTMILLENIUM;
}

b_param *b_time_t::b_time_tY2K()
{
   return &_b_time_tY2K;
}

b_param *b_time_t::b_time_tY2K_MINUS_ONE()
{
   return &_b_time_tY2K_MINUS_ONE;
}

b_param *b_time_t::b_time_tY2K_PLUS_ONE()
{
   return &_b_time_tY2K_PLUS_ONE;
}

//--------------------------------------------------------------------
//---------------------------------------------------------------------------
//type name return method

b_param *CLASSNAME::typeName()
{
  return &_b_time_tTYPENAME;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int CLASSNAME::distanceFromBase()
{
  return CLASSPARENT::distanceFromBase() +1;
}


//---------------------------------------------------------------------------
void CLASSNAME::typeList(b_param list[], int num)
{
  strcpy(list[num],(char *) typeName());
  CLASSPARENT::typeList(list,num+1);
}
//--------------------------------------------------------------------
  void *CLASSNAME::access(b_param data[])
{
  if (strcmp(data[0],(char *)typeName())!=0)
    return CLASSPARENT::access(data);

  //ACCESS CODE
b_time_t_now = 0;
b_time_t_tomorrow = 0;
b_time_t_nextweek = 0;
b_time_t_nextmonth = 0;
b_time_t_nextyear = 0;
b_time_t_nextdecade = 0;
b_time_t_nextcentury = 0;
b_time_t_nextmillenium = 0;
b_time_t_y2k = 0;
b_time_t_y2k_minus_one = 0;
b_time_t_y2k_plus_one = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_time_tNOW)==0)
      b_time_t_now = 1;
   else if (strcmp(data[dataPTR],_b_time_tTOMORROW)==0)
      b_time_t_tomorrow = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTWEEK)==0)
      b_time_t_nextweek = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTMONTH)==0)
      b_time_t_nextmonth = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTYEAR)==0)
      b_time_t_nextyear = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTDECADE)==0)
      b_time_t_nextdecade = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTCENTURY)==0)
      b_time_t_nextcentury = 1;
   else if (strcmp(data[dataPTR],_b_time_tNEXTMILLENIUM)==0)
      b_time_t_nextmillenium = 1;
   else if (strcmp(data[dataPTR],_b_time_tY2K)==0)
      b_time_t_y2k = 1;
   else if (strcmp(data[dataPTR],_b_time_tY2K_MINUS_ONE)==0)
      b_time_t_y2k_minus_one = 1;
   else if (strcmp(data[dataPTR],_b_time_tY2K_PLUS_ONE)==0)
      b_time_t_y2k_plus_one = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"SECONDS"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

 time_t time_since_epoch = time(NULL);

if (b_time_t_now==1)
{

 _theVariable= time_since_epoch;
 
}

if (b_time_t_tomorrow==1)
{

 time_since_epoch += DAY;
 _theVariable = time_since_epoch;
 
}

if (b_time_t_nextweek==1)
{

 time_since_epoch += (DAY*7);
 _theVariable = time_since_epoch;
 
}

if (b_time_t_nextmonth==1)
{

 time_since_epoch += (DAY*30);
 _theVariable= time_since_epoch;
 
}

if (b_time_t_nextyear==1)
{

 time_since_epoch += YEAR;
 _theVariable= time_since_epoch;
 
}

if (b_time_t_nextdecade==1)
{

 time_since_epoch += (YEAR*10);
 _theVariable= time_since_epoch;
 
}

if (b_time_t_nextcentury==1)
{

 time_since_epoch += (YEAR*100);
 _theVariable= time_since_epoch;
 
}

if (b_time_t_nextmillenium==1)
{

 time_since_epoch += (YEAR*1000);
 _theVariable= time_since_epoch;
 
}

if (b_time_t_y2k==1)
{

 time_since_epoch = MIDNIGHT_2000;
 _theVariable= time_since_epoch;
 
}

if (b_time_t_y2k_minus_one==1)
{

 time_since_epoch = MIDNIGHT_2000-1;
 _theVariable= time_since_epoch;

 
}

if (b_time_t_y2k_plus_one==1)
{

 time_since_epoch = MIDNIGHT_2000+1;
 _theVariable= time_since_epoch;
 
}
   return &_theVariable;
}

//--------------------------------------------------------------------
  int CLASSNAME::commit(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::commit(tname);
  //COMMIT CODE HERE
//generated
   return 0;
}

//--------------------------------------------------------------------
  int CLASSNAME::cleanup(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::cleanup(tname);
      
  //CLEANUP CODE
//generated
   return 0;
}

//--------------------------------------------------------------------
int CLASSNAME::numDials(b_param tname)
{
  if (!strcmp(tname,(char *)typeName()))
    return NUMBER_OF_DIALS;
  else return CLASSPARENT::numDials(tname);
      
}


//---------------------------------------------------------------------------
int CLASSNAME::numItems(b_param tname,int dialNumber)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::numItems(tname,dialNumber);
  switch (dialNumber)
    {
      //NUMITEMS SWITCH CASES HERE
      //generated

   case 1:
      return 11;
      break;
//---------------------------------------------------------------------------
      //end generated

    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::numItems\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);
    }
  return 0;
}

//---------------------------------------------------------------------------
b_param *CLASSNAME::paramName(b_param tname,
                                   int dialNumber,
                                   int position)

{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::paramName(tname,dialNumber,position);
  
  switch (dialNumber)
    {
      //PARAMNAME SWITCH CASES HERE
      //generated

case 1:
 switch (position)
   {
      case 1:
         return b_time_tNOW();
         break;
      case 2:
         return b_time_tTOMORROW();
         break;
      case 3:
         return b_time_tNEXTWEEK();
         break;
      case 4:
         return b_time_tNEXTMONTH();
         break;
      case 5:
         return b_time_tNEXTYEAR();
         break;
      case 6:
         return b_time_tNEXTDECADE();
         break;
      case 7:
         return b_time_tNEXTCENTURY();
         break;
      case 8:
         return b_time_tNEXTMILLENIUM();
         break;
      case 9:
         return b_time_tY2K();
         break;
      case 10:
         return b_time_tY2K_MINUS_ONE();
         break;
      case 11:
         return b_time_tY2K_PLUS_ONE();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;
    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::paramName\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);

    }
  return NULL;
}

//---------------------------------------------------------------------------
