ADMB Documentation  11.1.1932
 All Classes Files Functions Variables Typedefs Friends Defines
humung.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: humung.cpp 1896 2014-04-16 23:29:55Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file fvar.cpp
00012 // constructors, destructors and misc functions involving class prevariable
00013 #include "fvar.hpp"
00014 
00015 #if defined(__ZTC__)
00016 //  void _far * _cdecl _farptr_norm(void _far *);
00017   void _far * _cdecl _farptr_fromlong(unsigned long);
00018   long _cdecl _farptr_tolong(void _far *);
00019 #endif
00020 
00025 void humungous_pointer::free(void)
00026 {
00027   ptr-=adjustment;
00028   adjustment=0;
00029 #if defined(__BORLANDC__) || defined(__ZTC__)
00030   farfree(ptr);
00031 #else
00032   ::free(ptr);
00033 #endif
00034   ptr=NULL;
00035 }
00036 
00041 void humungous_pointer::adjust(int a)
00042 {
00043   ptr+=a;
00044   adjustment=a;
00045   //ptr=NULL;
00046 }
00047 
00052 humungous_pointer::humungous_pointer()
00053 {
00054   adjustment=0;
00055   //ptr=NULL;
00056 }
00057 
00062 int humungous_pointer::operator == (void * p)
00063 {
00064   return (ptr==p);
00065 }
00066 
00071 int humungous_pointer::operator != (void * p)
00072 {
00073   return (ptr!=p);
00074 }
00075 
00080 humungous_pointer::operator char* ()
00081 {
00082   return ptr;
00083 }
00084 
00089 humungous_pointer::operator void* ()
00090 {
00091   return (void *) ptr;
00092 }
00093 
00098 humungous_pointer::operator double_and_int* ()
00099 {
00100   return (double_and_int *)ptr;
00101 }
00102 
00107 humungous_pointer::operator double* ()
00108 {
00109   return (double *)ptr;
00110 }
00111 
00116 humungous_pointer humungous_pointer::operator + (unsigned long int& offset)
00117 // Note that pointer addition is in bytes not the size of the
00118 // object pointed to
00119 {
00120   humungous_pointer tmp;
00121 #if defined(__ZTC__)
00122     tmp.ptr=(char*)(_farptr_fromlong(_farptr_tolong(ptr)+offset));
00123 #else
00124     tmp.ptr=(ptr+offset);
00125 #endif
00126   return tmp;
00127 }
00128 
00133 humungous_pointer& humungous_pointer::operator += (unsigned long int& offset)
00134 // Note that pointer addition is in bytes not the size of the
00135 // object pointed to
00136 {
00137   //char * tmp;
00138 #if defined(__ZTC__)
00139     ptr=(char*)(_farptr_fromlong(_farptr_tolong(ptr)+offset));
00140 #else
00141     ptr=(ptr+offset);
00142 #endif
00143   return *this;
00144 }
00145 
00150 humungous_pointer& humungous_pointer::operator = (void * p)
00151 {
00152 #if defined(__BORLANDC__)
00153     ptr = (char huge *) p;
00154 #else
00155     ptr = (char *) p;
00156 #endif
00157   return *this;
00158 }