// $Revision: 1.6 $ // LocalStockData.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_LOCALSTOCKDATA #include "LocalStockData.h" #endif //============================================================================== // TLocalStockData TaligentTypeExtensionMacro(TLocalStockData); TLocalStockData::TLocalStockData() : TStockData(), fData(NIL) { } TLocalStockData::TLocalStockData(const TLocalStockData& source) : TStockData(source), fData(NIL) { PrivateCopy(source); } TLocalStockData::TLocalStockData(const TStandardText& name, TCollectionOf* adopt) : TStockData(name), fData(adopt) { } TLocalStockData::~TLocalStockData() { PrivateDelete(); } TLocalStockData& TLocalStockData::operator=(const TLocalStockData& source) { if (&source != this) { TStockData::operator=(source); PrivateCopy(source); } return *this; } TStream& TLocalStockData::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TStockData::operator>>=(toStream); ::Flatten(fData, toStream); return toStream; } TStream& TLocalStockData::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TStockData::operator<<=(fromStream); ::Resurrect(fData, fromStream); return fromStream; } bool TLocalStockData::operator==(const TStockData& other) const { bool isEqual = TStockData::operator==(other); if (isEqual) { const TLocalStockData* otherLocal; ::DynamicCastTo(otherLocal, &other); if (otherLocal != NIL) { isEqual = (fData == NIL && otherLocal->fData == NIL) || (fData != NIL && otherLocal->fData != NIL && *fData == *otherLocal->fData); } } return isEqual; } TLocalStockData& TLocalStockData::operator=(const TStockData& source) { if (&source != this) { TStockData::operator=(source); if (fData != NIL) { fData->RemoveAll(); source.CopyData(*fData); } else { TDeleterFor > data = new TDequeOf( NIL, new TMonomorphicStreamer); source.CopyData(*data); if (!data->IsEmpty()) { fData = data.OrphanObject(); } } } return *this; } bool TLocalStockData::CopyData(TCollectionOf& fill, const TRangeOfDays& range) const { bool success = false; if (fData != NIL) { TDeleterFor > iter = fData->CreateIterator(); for (TStockDay* day = iter->First(); day; day = iter->Next()) { if (range.Contains(day->GetDate())) { fill.Add(new TStockDay(*day)); } } success = fill.Count() > 0; } return success; } void TLocalStockData::AdoptData(TCollectionOf* adoptee) { PrivateDelete(); fData = adoptee; } TCollectionOf* TLocalStockData::OrphanData() { TCollectionOf* orphanedData = fData; fData = NIL; return orphanedData; } void TLocalStockData::PrivateDelete() { if (fData != NIL) { fData->DeleteAll(); delete fData; fData = NIL; } } void TLocalStockData::PrivateCopy(const TLocalStockData& source) { PrivateDelete(); if (source.fData != NIL) { fData = ::Copy(*source.fData); fData->RemoveAll(); TDeleterFor > iter = source.fData->CreateIterator(); for (TStockDay* day = iter->First(); day; day = iter->Next()) { fData->Add(new TStockDay(*day)); } } }