ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
humung.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
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 
00024 humungous_pointer::humungous_pointer():
00025   adjustment(0),
00026   ptr(NULL)
00027 {
00028 }
00029 
00034 void humungous_pointer::free()
00035 {
00036   ptr -= adjustment;
00037   adjustment = 0;
00038 #if defined(__BORLANDC__) || defined(__ZTC__)
00039   farfree(ptr);
00040 #else
00041   ::free(ptr);
00042 #endif
00043   ptr = NULL;
00044 }
00045 
00050 void humungous_pointer::adjust(const size_t a)
00051 {
00052   adjustment = a;
00053   ptr += adjustment;
00054 }
00055 
00060 int humungous_pointer::operator == (void * p)
00061 {
00062   return (ptr==p);
00063 }
00064 
00069 int humungous_pointer::operator != (void * p)
00070 {
00071   return (ptr!=p);
00072 }
00073 
00078 humungous_pointer::operator char* ()
00079 {
00080   return ptr;
00081 }
00082 
00087 humungous_pointer::operator void* ()
00088 {
00089   return (void*)ptr;
00090 }
00091 
00096 humungous_pointer::operator double_and_int* ()
00097 {
00098   return (double_and_int*)ptr;
00099 }
00100 
00105 humungous_pointer::operator double* ()
00106 {
00107   return (double*)ptr;
00108 }
00109 
00113 humungous_pointer humungous_pointer::operator + (unsigned long int& offset)
00114 {
00115   humungous_pointer tmp;
00116 #if defined(__ZTC__)
00117   tmp.ptr=(char*)(_farptr_fromlong(_farptr_tolong(ptr)+offset));
00118 #else
00119   tmp.ptr=(ptr+offset);
00120 #endif
00121   return tmp;
00122 }
00123 
00127 humungous_pointer& humungous_pointer::operator += (unsigned long int& offset)
00128 {
00129 #if defined(__ZTC__)
00130   ptr=(char*)(_farptr_fromlong(_farptr_tolong(ptr)+offset));
00131 #else
00132   ptr=(ptr+offset);
00133 #endif
00134   return *this;
00135 }
00136 
00141 humungous_pointer& humungous_pointer::operator = (void * p)
00142 {
00143 #if defined(__BORLANDC__)
00144   ptr = (char huge *) p;
00145 #else
00146   ptr = (char*) p;
00147 #endif
00148   return *this;
00149 }