Subrange.C
inter/Subrange.C · 927 B
From the archive interlude_1beta5.tar.gz
Download the archive « Back to the archive contents
#include "Subrange.h"
#pragma implementation
Subrange::Subrange (Value* inval , int begin , int end){
length = end - begin + 1;
switch (inval->type)
{case LIST:
for (sublist = inval->list ; begin > 1 ; begin--)
sublist = sublist->next;
original = inval->grab();
return;
case SUBR:
original = inval->sub->original->grab();
for (sublist = inval->sub->sublist ; begin > 1 ; begin--)
sublist = sublist->next;
return;}
}
Subrange::~Subrange (){
original->release();
}
Value* Subrange::copy_full_val(){
return new Value (sublist->copy_some (length));
}
Val_List* Subrange::copy_full_list(){
return sublist->copy_some (length);
}
int Subrange::get_length(){
return length;
}
Value* Subrange::nth(int i){
Val_List* temp;
if (i < 1) return NULL;
for (temp = sublist , i-- ; i ; i-- , temp=temp->next)
if (!temp->next)
return NULL;
return temp->elem;
}