📄 structure.cpp
字号:
// Propagate query.
for (i = 0; i < GetNoChildren(); i++) {
if (GetChild(i)->IsParent(child, recursive))
return true;
}
return false;
}
//-------------------------------------------------------------------
// Method........: HasChildren
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns true if the structure has any children.
// Comments......:
// Revisions.....:
//===================================================================
bool
Structure::HasChildren() const {
return (GetNoChildren() > 0);
}
//-------------------------------------------------------------------
// Method........: HasChild
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Returns true if the structure has a child of the
// specified type.
// Revisions.....:
//===================================================================
bool
Structure::HasChild(Id id, bool recursive) const {
int i;
// Query immediate children.
for (i = 0; i < GetNoChildren(); i++) {
if (GetChild(i)->IsA(id))
return true;
}
if (!recursive)
return false;
// Propagate query.
for (i = 0; i < GetNoChildren(); i++) {
if (GetChild(i)->HasChild(id, recursive))
return true;
}
return false;
}
//-------------------------------------------------------------------
// Member management methods.
//===================================================================
//-------------------------------------------------------------------
// Method........: GetNoStructures
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Makes the interface more uniform for structures
// with or without internal member structures.
//
// Should be overloaded by structures with internal
// members (structure sets).
// Revisions.....:
//===================================================================
int
Structure::GetNoStructures() const {
return 0;
}
//-------------------------------------------------------------------
// Method........: GetStructure
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Makes the interface more uniform for structures with
// or without internal member structures.
//
// Should be overloaded by structures with internal
// members (structure sets).
// Revisions.....:
//===================================================================
Structure *
Structure::GetStructure(int /*i*/) const {
Message::Error("This method should never have been invoked.");
return NULL;
}
//-------------------------------------------------------------------
// Method........: FindMember
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Given a structure, returns the position in
// the set of that structure.
//
// Example: structures = {StructureA, StructureB}
// structures.FindMember(&StructureA) returns 0;
// structures.FindMember(&StructureB) returns 1;
// structures.FindMember(&StructureC) returns Undefined::Integer();
//
// Membership can be both physical and logical.
//
// Comments......: Logical membership currently not handled -- a
// small redesign may be called for.
// Revisions.....:
//===================================================================
int
Structure::FindMember(const Structure *member, bool physical) const {
int i, no_structures = GetNoStructures();
for (i = 0; i < no_structures; i++) {
if (physical) {
if (member == GetStructure(i))
return i;
}
else {
Message::Error("Check for logical membership in FindMember not implemented yet.");
break;
}
}
return Undefined::Integer();
}
//-------------------------------------------------------------------
// Method........: IsMember
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Returns true if the given structure is an internal
// member structure of this structure.
//
// Membership can be both physical and logical.
// Revisions.....:
//===================================================================
bool
Structure::IsMember(const Structure *member, bool physical) const {
return (FindMember(member, physical) != Undefined::Integer());
}
//-------------------------------------------------------------------
// Method........: HasMembers
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Returns true if this structure has any internal
// member structures.
// Revisions.....:
//===================================================================
bool
Structure::HasMembers() const {
return (GetNoStructures() > 0);
}
//-------------------------------------------------------------------
// Method........: InsertStructure
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Makes the interface more uniform for structures with
// or without internal member structures.
//
// Should be overloaded by structures with internal
// members (structure sets).
// Revisions.....:
//===================================================================
bool
Structure::InsertStructure(Structure * /*member*/, int /*i*/) {
return false;
}
//-------------------------------------------------------------------
// Method........: AppendStructure
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Makes the interface more uniform for structures with
// or without internal member structures.
// Revisions.....:
//===================================================================
bool
Structure::AppendStructure(Structure *member) {
return InsertStructure(member, GetNoStructures());
}
//-------------------------------------------------------------------
// Method........: RemoveStructure
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Makes the interface more uniform for structures with
// or without internal member structures.
//
// Should be overloaded by structures with internal
// members (structure sets).
// Revisions.....:
//===================================================================
bool
Structure::RemoveStructure(int /*i*/) {
return false;
}
//-------------------------------------------------------------------
// Method........: RemoveAllStructures
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Removes all internal member structures.
// Comments......:
// Revisions.....:
//===================================================================
bool
Structure::RemoveAllStructures() {
int i, no_members = GetNoStructures();
for (i = no_members - 1; i >= 0; i--) {
if (!RemoveStructure(i))
return false;
}
return true;
}
//-------------------------------------------------------------------
// Method........: Merge
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Does not eliminate duplicates, yet.
// Revisions.....:
//===================================================================
bool
Structure::Merge(const Structure &structure, bool verify) {
// Verify types.
if (verify && !structure.IsA(GetId()))
return false;
int i, no_structures = structure.GetNoStructures();
// Append duplicates.
for (i = 0; i < no_structures; i++) {
if (!AppendStructure(structure.GetStructure(i)->Duplicate()))
return false;
}
return true;
}
//-------------------------------------------------------------------
// Parent search methods.
//===================================================================
//-------------------------------------------------------------------
// Method........: IsAnnotated
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
Structure::IsAnnotated() const {
return (GetAnnotation() != NULL);
}
//-------------------------------------------------------------------
// Method........: GetAnnotation
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Should be overloaded by annotatable structures.
// Revisions.....:
//===================================================================
Annotation *
Structure::GetAnnotation() const {
return NULL;
}
//-------------------------------------------------------------------
// Method........: SetAnnotation
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Should be overloaded by annotatable structures.
// Revisions.....:
//===================================================================
bool
Structure::SetAnnotation(Annotation * /*annotation*/) {
return false;
}
//-------------------------------------------------------------------
// Method........: Touch
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Should be overloaded by annotatable structures.
// Revisions.....:
//===================================================================
bool
Structure::Touch(const String &/*action*/) {
return false;
}
//-------------------------------------------------------------------
// Parent search methods.
//===================================================================
//-------------------------------------------------------------------
// Method........: FindParent
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
Structure *
Structure::FindParent() const {
Handle<Project> project = ProjectManager::GetProject(this);
if (project == NULL)
return NULL;
return FindParent(*project);
}
//-------------------------------------------------------------------
// Method........: FindParent
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Given an ancestor structure that this structure is
// directly or indirectly derived from, returns this
// structure's immediate parent.
// Comments......:
// Revisions.....:
//===================================================================
Structure *
Structure::FindParent(const Structure &ancestor) const {
// No object is its own parent.
if (&ancestor == this)
return NULL;
return StaticRecursiveFindParent(this, &ancestor);
}
//-------------------------------------------------------------------
// Method........: FindParent
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Given an ancestor structure that this structure is
// directly or indirectly derived from, returns the
// closest ancestor to this structure of a specified
// type.
// Comments......: Can be implemented more efficiently, but that's
// probably not necessary.
// Revisions.....:
//===================================================================
Structure *
Structure::FindParent(Id id, const Structure &ancestor) const {
// Find the immediate parent.
Structure *parent = FindParent(ancestor);
// Until a parent of the given type is found, get the parent's parent.
while (parent != NULL) {
if (parent->IsA(id))
return parent;
parent = parent->FindParent(ancestor);
}
// No parent of the specified type found.
return NULL;
}
//-------------------------------------------------------------------
// Method........: FindParent
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the most immediate ancestor that is of the
// specified type.
// Comments......:
// Revisions.....:
//===================================================================
Structure *
Structure::FindParent(Id id) const {
Handle<Project> project = ProjectManager::GetProject(this);
if (project == NULL)
return NULL;
return FindParent(id, *project);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -