📄 page.cpp
字号:
//===========================================================================//
// File: notation.cpp //
// Title: Definition of NotationFile classes. //
// Purpose: Provide general purpose access to data stored in a formatted //
// text file. //
//---------------------------------------------------------------------------//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#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);
NoteIterator notes(&m_notes);
notes.DeletePlugs();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
Page::WriteNotes(MemoryStream *stream)
{
Check_Object(this);
const char* name = m_name;
if (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<Note*>*
Page::MakeNoteChain(const char *entryname)
{
Check_Object(this);
Check_Pointer(entryname);
NoteIterator notes(&m_notes);
Note *note;
ChainOf<Note*>* chain = new ChainOf<Note*>(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 Note(this);
Check_Object(note);
note->SetName(entryname);
m_notes.Add(note);
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(),
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,
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((
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -