home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-08 | 4.3 KB | 223 lines | [TEXT/CWIE] |
- /*
- CEntry.cp
-
- Copyright © 1995 Alastair Rankine.
- All Rights Reserved.
- */
-
- #include "CEntry.h"
- #include "CLookupDocument.h"
- #include <UAEGizmos.h>
- #include <ostream>
-
- const CEntry sEmptyEntry;
- const char CEntry::kFieldSeparator = '\t';
- const char CEntry::kEntrySeparator = '\n';
- const DescType CEntry::kFieldProperties[] = {
- pName,
- 'PHN1',
- 'PHN2',
- 'EMAI'
- };
-
- CEntry::CEntry(LModelObject * inSuperModel)
- : LModelObject(inSuperModel, kModelID)
- {
- }
-
- const CString & CEntry::GetField(UInt16 inFieldNumber) const
- {
- Assert_(inFieldNumber < kFieldCount);
-
- return mField[inFieldNumber];
- }
-
- CEntry::CEntry(const CEntry & another)
- : LModelObject(another.mSuperModel, kModelID)
- {
- for(UInt16 i = 0; i < kFieldCount; i++)
- mField[i] = another.mField[i];
- }
-
- CEntry & CEntry::operator = (const CEntry & another)
- {
- if(&another != this)
- for(UInt16 i = 0; i < kFieldCount; i++)
- mField[i] = another.mField[i];
-
- return *this;
- }
-
- CEntry::~CEntry()
- {
- }
-
- void CEntry::SetField(UInt16 inField, const CString & inValue)
- {
- Assert_(inField < kFieldCount);
-
- mField[inField] = inValue;
- }
-
- void CEntry::GetAEProperty(DescType inProperty, const AEDesc & inRequestedType,
- AEDesc & outPropertyDesc) const
- {
- UInt16 i = 0;
-
- for(; i < kFieldCount; i++)
- {
- if(kFieldProperties[i] == inProperty)
- {
- CString & field = (CString &)mField[i];
-
- LAEStream out;
- out.WriteDesc(typeChar, field.c_str(), field.length());
- out.Close(&outPropertyDesc);
-
- return;
- }
- }
-
- if(i >= kFieldCount)
- LModelObject::GetAEProperty(inProperty, inRequestedType, outPropertyDesc);
- }
-
- void CEntry::SetAEProperty(DescType inProperty, const AEDesc & inValue, AEDesc & outAEReply)
- {
- if(inProperty == pContents)
- {
- // inValue is a record of properties... extract and set them by recursively
- // calling this procedure.
- LAESubDesc properties(inValue, typeAERecord);
-
- unsigned long propCount = properties.CountItems();
- for(unsigned long i = 1; i <= propCount; i++)
- {
- AEKeyword keyword;
- LAESubDesc theProperty = properties.NthItem(i, &keyword);
-
- StAEDescriptor propDesc;
- theProperty.ToDesc(propDesc);
-
- StAEDescriptor bogusReply;
- SetAEProperty(keyword, propDesc, bogusReply.mDesc);
- }
- }
- else
- {
- // Search through the properties array looking for a match:
- UInt16 i = 0;
- for(; i < kFieldCount; i++)
- {
- if(kFieldProperties[i] == inProperty)
- {
- mField[i].ExtractFromAEDesc(inValue);
-
- // This is a little ugly.
- if(mSuperModel)
- {
- CLookupDocument * doc = (CLookupDocument *)mSuperModel;
- doc->NotifyEntryChanged(this);
- }
-
- break;
- }
- }
-
- // Not a known property, pass it up the chain!
- if(i >= kFieldCount)
- LModelObject::SetAEProperty(inProperty, inValue, outAEReply);
- }
- }
-
- void CEntry::GetImportantAEProperties(AERecord & outRecord)
- {
- LAEStream stream;
-
- stream.OpenRecord();
- for (UInt16 i = 0; i < kFieldCount; i++) {
- StAEDescriptor prop(mField[i].ToPString());
-
- stream.WriteKeyDesc(kFieldProperties[i], prop);
- }
- stream.CloseRecord();
- stream.Close(&outRecord);
- }
-
- void CEntry::HandleDelete(AppleEvent &, AEDesc &)
- {
- // This is a little ugly.
- if(mSuperModel)
- {
- CLookupDocument * doc = (CLookupDocument *)mSuperModel;
- doc->DeleteEntry(this);
- }
- }
-
- void CEntry::GetDifferentAEProperties(const CEntry & inCompare, AERecord & outRecord) const
- {
- LAEStream stream;
-
- stream.OpenRecord();
- for (UInt16 i = 0; i < kFieldCount; i++)
- if(mField[i] != inCompare.mField[i])
- {
- StAEDescriptor prop(mField[i].ToPString());
-
- stream.WriteKeyDesc(kFieldProperties[i], prop);
- }
- stream.CloseRecord();
- stream.Close(&outRecord);
- }
-
-
-
-
-
- const StringPtr CEntry::GetModelNamePtr() const
- {
- Assert_(kFieldProperties[0] == pName);
-
- return mField[0].ToPString();
- }
-
- ostream & operator << (ostream & stream, CEntry const & rec)
- {
- for(UInt16 i = 0; i < CEntry::kFieldCount; i++)
- {
- if(i)
- stream << CEntry::kFieldSeparator;
-
- stream << rec.mField[i];
- }
- stream << CEntry::kEntrySeparator;
-
- return stream;
- }
-
- istream & operator >> (istream & stream, CEntry & rec)
- {
- UInt16 currField = 0;
- char ch = 0;
-
- while(stream.good() && (ch != CEntry::kEntrySeparator))
- {
- stream.get(ch);
-
- switch(ch)
- {
- case CEntry::kFieldSeparator:
- if(++currField >= CEntry::kFieldCount)
- ch = CEntry::kEntrySeparator;
- break;
- case CEntry::kEntrySeparator:
- break;
- default:
- rec.mField[currField].append(ch);
- break;
- }
- }
-
- return stream;
- }
-