00001 /* 00002 // $Id: //open/dev/fennel/calculator/RegisterReference.cpp#2 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2004-2009 SQLstream, Inc. 00006 // Copyright (C) 2009-2009 LucidEra, Inc. 00007 // 00008 // This program is free software; you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by the Free 00010 // Software Foundation; either version 2 of the License, or (at your option) 00011 // any later version approved by The Eigenbase Project. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 // 00022 // An index and perhaps a pointer into a RegisterSet 00023 // Optionally optimizes subsequent reads and writes 00024 */ 00025 #include "fennel/common/CommonPreamble.h" 00026 #include "fennel/calculator/RegisterReference.h" 00027 #include "fennel/calculator/Calculator.h" 00028 00029 #include "boost/format.hpp" 00030 using boost::format; 00031 00032 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/calculator/RegisterReference.cpp#2 $"); 00033 00034 RegisterSetBinding::~RegisterSetBinding() 00035 { 00036 if (ownTheBase) { 00037 delete base; 00038 } 00039 delete[] datumAddr; 00040 } 00041 00042 RegisterSetBinding::RegisterSetBinding(TupleData* base, bool ownIt) 00043 : ownTheBase(ownIt), base(base) 00044 { 00045 assert(base); 00046 ncols = base->size(); 00047 datumAddr = new PConstBuffer[ncols]; 00048 for (int i = 0; i < ncols; i++) { 00049 const TupleDatum& baseCol = (*base)[i]; 00050 datumAddr[i] = baseCol.pData; 00051 } 00052 } 00053 00054 RegisterSetBinding::RegisterSetBinding( 00055 TupleData* base, 00056 const TupleData* shadow, 00057 bool ownIt) 00058 : ownTheBase(ownIt), 00059 base(base) 00060 { 00061 assert(base); 00062 ncols = base->size(); 00063 assert(shadow->size() == ncols); 00064 datumAddr = new PConstBuffer[ncols]; 00065 for (int i = 0; i < ncols; i++) { 00066 const TupleDatum& baseCol = (*base)[i]; 00067 const TupleDatum& shadowCol = (*shadow)[i]; 00068 datumAddr[i] = shadowCol.pData; 00069 // check that SHADOW coincides with BASE 00070 if (baseCol.pData) { 00071 assert(baseCol.pData == shadowCol.pData); 00072 } else { 00073 assert(shadowCol.pData); 00074 } 00075 } 00076 } 00077 00078 void 00079 RegisterReference::setCalc(Calculator* calcP) { 00080 mRegisterSetP = calcP->mRegisterSetBinding; 00081 mRegisterSetDescP = calcP->mRegisterSetDescriptor; 00082 mResetP = &(calcP->mRegisterReset); 00083 mPDynamicParamManager = calcP->getDynamicParamManager(); 00084 if (mSetIndex == EOutput && calcP->mOutputRegisterByReference) { 00086 mProp |= (EPropByRefOnly | EPropReadOnly); 00087 } 00088 } 00089 00090 void 00091 RegisterReference::cachePointer() { 00092 if (mProp & (EPropCachePointer | EPropPtrReset)) { 00093 TupleDatum *bind = getBinding(); 00094 mPData = const_cast<PBuffer>(bind->pData); 00095 mCbData = bind->cbData; 00096 00097 // Next 3 lines clarify complex 4th line: 00098 // TupleDescriptor* tupleDescP = mRegisterSetDescP[mSetIndex]; 00099 // TupleAttributeDescriptor* attrP = &((*tupleDescP)[mIndex]); 00100 // mCbStorage = attrP->cbStorage; 00101 mCbStorage = ((*(mRegisterSetDescP[mSetIndex]))[mIndex]).cbStorage; 00102 mCachePtrModified = false; 00103 } 00104 } 00105 00106 void 00107 RegisterReference::setDefaultProperties() 00108 { 00109 switch (mSetIndex) { 00110 case ELiteral: 00111 mProp = KLiteralSetDefault; 00112 break; 00113 case EInput: 00114 mProp = KInputSetDefault; 00115 break; 00116 case EOutput: 00117 mProp = KOutputSetDefault; 00118 break; 00119 case ELocal: 00120 mProp = KLocalSetDefault; 00121 break; 00122 case EStatus: 00123 mProp = KStatusSetDefault; 00124 break; 00125 default: 00126 mProp = EPropNone; 00127 } 00128 } 00129 00130 00131 00132 string 00133 RegisterReference::toString() const 00134 { 00135 return boost::io::str(format("[S%d I%lu]") % mSetIndex % mIndex); 00136 } 00137 00138 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/calculator/RegisterReference.cpp#2 $"); 00139 00140 // End RegisterReference.cpp