//===========================================================================// // File: notation.cpp // // Title: Definition of NotationFile classes. // // Project: Munga // // Author: Ken Olsen // // Purpose: Provide general purpose access to data stored in a formatted // // text file. // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 01/07/95 KEO Converted from Tool Architecture I. // // 02/07/95 KEO Add AppendEntry methods. // // 02/17/95 KEO Change page and entry lists to make nomenclature. // // 03/11/95 KEO Remove all instances of strtok from class. // // 03/24/95 KEO Add methods to read and write text in memory. // // 03/31/95 KEO Add methods for lab only mark. // // 05/23/95 KEO Add setpage and appendpage and allow setentry(,,null). // // 11/11/95 KEO Add operation modes and correct small bugs. // // 04/02/97 GAH Added "DeleteAllPages" method. // //---------------------------------------------------------------------------// // Copyright (c) 1994-1995 Virtual World Entertainment, Inc. // // Copyright (c) 1996-1997 Fasa Interactive Technologies, Inc. // // All rights reserved worldwide. // // This unpublished source code is PROPRIETARY and CONFIDENTIAL. // //===========================================================================// #include "StuffHeaders.hpp" #define MAX_LINE_SIZE 512 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Page::Page(NotationFile *notation_file): Plug(DefaultData), m_notes(NULL) { Check_Pointer(this); Check_Object(notation_file); m_notationFile = notation_file; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Page::~Page() { Check_Object(this); m_notes.DeletePlugs(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::WriteNotes(MemoryStream *stream) { Check_Object(this); const char* name = m_name; if (name && *name) *stream << '[' << name << "]\r\n"; NoteIterator notes(&m_notes); Note *note; while ((note = notes.ReadAndNext()) != NULL) { Check_Object(note); note->WriteNotation(stream); } *stream << "\r\n"; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Note* Page::FindNote(const char *entryname) { Check_Object(this); Check_Pointer(entryname); NoteIterator notes(&m_notes); Note *note; while ((note = notes.ReadAndNext()) != NULL) { Check_Object(note); if (!_stricmp(note->m_name, entryname)) return note; } return NULL; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Note* Page::GetNote(unsigned i) { Check_Object(this); NoteIterator notes(&m_notes); return notes.GetNth(i); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ChainOf* Page::MakeNoteChain(const char *entryname) { Check_Object(this); Check_Pointer(entryname); NoteIterator notes(&m_notes); Note *note; ChainOf* chain = new(g_Heap) ChainOf(NULL); Check_Object(chain); int len = strlen(entryname); while ((note = notes.ReadAndNext()) != NULL) { Check_Object(note); if (!_strnicmp(note->GetName(), entryname, len)) chain->Add(note); } return chain; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Note* Page::AddNote(const char *entryname) { Check_Object(this); Check_Pointer(entryname); SetDirty(); Note *note = new(g_Heap) Note(this); Check_Object(note); note->SetName(entryname); m_notes.Add(note); return note; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Note* Page::SetNote(const char *entryname) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); return note; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::DeleteNote(const char *entryname) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (note) { Check_Object(note); delete note; SetDirty(); } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::DeleteAllNotes() { Check_Object(this); NoteIterator notes(&m_notes); Note *note; while ((note = notes.ReadAndNext()) != NULL) { Check_Object(note); delete note; } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, const char **contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), (const char*)m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const char *contents ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(contents); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const char *contents ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(contents); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, int *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, int contents ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(contents); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, int contents ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(contents); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, Scalar *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, Scalar value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, Scalar value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, DWORD *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, DWORD value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, DWORD value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, bool *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, bool value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, bool value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, Vector3D *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const Vector3D &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const Vector3D &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, YawPitchRoll *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const YawPitchRoll &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const YawPitchRoll &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, UnitQuaternion *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const UnitQuaternion &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const UnitQuaternion &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, Motion3D *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const Motion3D &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const Motion3D &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, RGBColor *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const RGBColor &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const RGBColor &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, RGBAColor *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, const RGBAColor &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, const RGBAColor &value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bool Page::GetEntry( const char *entryname, NotationFile *contents, bool required ) { Check_Object(this); Check_Pointer(entryname); Check_Pointer(contents); Note *note = FindNote(entryname); if (note) { Check_Object(note); note->GetEntry(contents); return true; } if (required) STOP(( "%s: [%s]%s is a required entry!", m_notationFile->GetFileName(), (char*)m_name, entryname )); return false; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::SetEntry( const char *entryname, NotationFile *value ) { Check_Object(this); Check_Pointer(entryname); Note *note = FindNote(entryname); if (!note) note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::AppendEntry( const char *entryname, NotationFile *value ) { Check_Object(this); Check_Pointer(entryname); Note *note = AddNote(entryname); Check_Object(note); note->SetEntry(value); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void Page::TestInstance() const { }