/*
   b_ptr_char.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 Tuesday, May 22 at 04:52 PM EDT

TITLE
   b_ptr_char.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_ptr_char.h"

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


 static char *save_b_ptr_char=NULL;
#define sup_fillstring(buf,len,fillChar) for (int i=0; i<len; i++) buf[i] = fillChar
 //--------------------------------------------------------------------

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

  //generated

   strcpy(_b_ptr_charTYPENAME,CLASS_STRING);
strcpy(_b_ptr_charS1,"b_ptr_char_S1");
strcpy(_b_ptr_charS4,"b_ptr_char_S4");
strcpy(_b_ptr_charS16,"b_ptr_char_S16");
strcpy(_b_ptr_charS8K,"b_ptr_char_S8K");
strcpy(_b_ptr_charCHAR,"b_ptr_char_CHAR");
strcpy(_b_ptr_charNUM,"b_ptr_char_NUM");
strcpy(_b_ptr_charNASTY,"b_ptr_char_NASTY");
strcpy(_b_ptr_charESC,"b_ptr_char_ESC");
strcpy(_b_ptr_charEMPTY,"b_ptr_char_EMPTY");
strcpy(_b_ptr_charSOME,"b_ptr_char_SOME");
strcpy(_b_ptr_charFULL,"b_ptr_char_FULL");
}

//--------------------------------------------------------------------
b_param *b_ptr_char::b_ptr_charS1()
{
   return &_b_ptr_charS1;
}

b_param *b_ptr_char::b_ptr_charS4()
{
   return &_b_ptr_charS4;
}

b_param *b_ptr_char::b_ptr_charS16()
{
   return &_b_ptr_charS16;
}

b_param *b_ptr_char::b_ptr_charS8K()
{
   return &_b_ptr_charS8K;
}

b_param *b_ptr_char::b_ptr_charCHAR()
{
   return &_b_ptr_charCHAR;
}

b_param *b_ptr_char::b_ptr_charNUM()
{
   return &_b_ptr_charNUM;
}

b_param *b_ptr_char::b_ptr_charNASTY()
{
   return &_b_ptr_charNASTY;
}

b_param *b_ptr_char::b_ptr_charESC()
{
   return &_b_ptr_charESC;
}

b_param *b_ptr_char::b_ptr_charEMPTY()
{
   return &_b_ptr_charEMPTY;
}

b_param *b_ptr_char::b_ptr_charSOME()
{
   return &_b_ptr_charSOME;
}

b_param *b_ptr_char::b_ptr_charFULL()
{
   return &_b_ptr_charFULL;
}

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

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

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
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_ptr_char_s1 = 0;
b_ptr_char_s4 = 0;
b_ptr_char_s16 = 0;
b_ptr_char_s8k = 0;
b_ptr_char_char = 0;
b_ptr_char_num = 0;
b_ptr_char_nasty = 0;
b_ptr_char_esc = 0;
b_ptr_char_empty = 0;
b_ptr_char_some = 0;
b_ptr_char_full = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_ptr_charS1)==0)
      b_ptr_char_s1 = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charS4)==0)
      b_ptr_char_s4 = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charS16)==0)
      b_ptr_char_s16 = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charS8K)==0)
      b_ptr_char_s8k = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"SIZE"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_ptr_charCHAR)==0)
      b_ptr_char_char = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charNUM)==0)
      b_ptr_char_num = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charNASTY)==0)
      b_ptr_char_nasty = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charESC)==0)
      b_ptr_char_esc = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"CONTENTS"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

   dataPTR++;
if (strcmp(data[dataPTR],_b_ptr_charEMPTY)==0)
      b_ptr_char_empty = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charSOME)==0)
      b_ptr_char_some = 1;
   else if (strcmp(data[dataPTR],_b_ptr_charFULL)==0)
      b_ptr_char_full = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"FILL"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

 char fillVar;
 int divisor;
 int size;
 char *temp_b_ptr_char=NULL;
 FILE* logFile = NULL;

 if ((logFile = fopen ("/tmp/templateLog.txt","a+")) == NULL)
 {
 exit(99);
 }

if (b_ptr_char_s1==1)
{

 size = 1;
 temp_b_ptr_char = (char *)malloc(size);
 if(temp_b_ptr_char == NULL)
 {
 fprintf(logFile,"b_ptr_char - S1 malloc failed, function not tested\n");
 fclose(logFile);
 exit(99);
 } 
 
}

if (b_ptr_char_s4==1)
{
 
 size = 4;
 temp_b_ptr_char = (char *)malloc(size);
 if(temp_b_ptr_char == NULL)
 {
 fprintf(logFile, "b_ptr_char - S4 malloc failed, function not tested\n");
 fclose(logFile);
 exit(99);
 } 
 
}

if (b_ptr_char_s16==1)
{

 size = 16;
 temp_b_ptr_char = (char *)malloc(size);
 if(temp_b_ptr_char == NULL)
 {
 fprintf(logFile,"b_ptr_char - S16 malloc failed, function not tested\n");
 fclose(logFile);
 exit(99);
 } 
 
}

if (b_ptr_char_s8k==1)
{

 size = 8192;
 temp_b_ptr_char = (char *)malloc(size);
 if(temp_b_ptr_char == NULL)
 {
 fprintf(logFile,"b_ptr_char - S8K malloc failed, function not tested\n");
 fclose(logFile);
 exit(99);
 } 
 
}

if (b_ptr_char_char==1)
{

 fillVar = 'A';
 
}

if (b_ptr_char_num==1)
{

 fillVar = '1';
 
}

if (b_ptr_char_nasty==1)
{

 fillVar = char(22);
 
}

if (b_ptr_char_esc==1)
{

 fillVar = char(27);
 
}

if (b_ptr_char_some==1)
{

 sup_fillstring(temp_b_ptr_char, (int)(size/3), fillVar);
 temp_b_ptr_char[(int)(size/3)+1]='\0';
 
}

if (b_ptr_char_full==1)
{

 sup_fillstring(temp_b_ptr_char, size, fillVar);
 
}

if (b_ptr_char_empty==1)
{

 temp_b_ptr_char[0]='\0';
 
}

 fclose(logFile);
 save_b_ptr_char = temp_b_ptr_char;
 _theVariable = temp_b_ptr_char;
   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

 if (save_b_ptr_char !=NULL)
 {
 free(save_b_ptr_char);
 }
    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 4;
      break;

   case 2:
      return 4;
      break;

   case 3:
      return 3;
      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_ptr_charS1();
         break;
      case 2:
         return b_ptr_charS4();
         break;
      case 3:
         return b_ptr_charS16();
         break;
      case 4:
         return b_ptr_charS8K();
         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;

case 2:
 switch (position)
   {
      case 1:
         return b_ptr_charCHAR();
         break;
      case 2:
         return b_ptr_charNUM();
         break;
      case 3:
         return b_ptr_charNASTY();
         break;
      case 4:
         return b_ptr_charESC();
         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;

case 3:
 switch (position)
   {
      case 1:
         return b_ptr_charEMPTY();
         break;
      case 2:
         return b_ptr_charSOME();
         break;
      case 3:
         return b_ptr_charFULL();
         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;
}

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