MediaBase.cpp
资源名称:MediaTree.zip [点击查看]
上传用户:boyawuliu
上传日期:2021-10-14
资源大小:8k
文件大小:3k
源码类别:
TreeView控件
开发平台:
Visual C++
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // File name : MediaBase.cpp
- // Purpose : Class implement for the base of all media objects
- //
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #include "MediaBase.h"
- #include <iostream>
- #include <ios>
- using namespace std;
- MediaBase::MediaBase(void)
- {
- m_MediaName = NULL;
- m_MediaFile = NULL;
- m_KeywordList = new std::list<char*>();
- m_ChildList = new std::list<MediaBase*>();
- m_Type = -1;
- }
- MediaBase::~MediaBase(void)
- {
- if (m_MediaName != NULL)
- {
- delete m_MediaName;
- }
- if (m_MediaFile != NULL)
- {
- delete m_MediaFile;
- }
- if (m_KeywordList != NULL)
- {
- m_KeywordList->clear();
- delete m_KeywordList;
- }
- if (m_ChildList != NULL)
- {
- m_ChildList->clear();
- delete m_ChildList;
- }
- }
- void MediaBase::SetMediaName(char* mediaName)
- {
- if (m_MediaName != NULL)
- {
- delete m_MediaName;
- }
- this->m_MediaName = mediaName;
- }
- char* MediaBase::GetMediaName()
- {
- return m_MediaName;
- }
- void MediaBase::SetMediaFile(char* mediaFile)
- {
- if (m_MediaFile != NULL)
- {
- delete m_MediaFile;
- }
- this->m_MediaFile = mediaFile;
- }
- char* MediaBase::GetMediaFile()
- {
- return m_MediaFile;
- }
- void MediaBase::AddKeyword(char* keyword)
- {
- m_KeywordList->push_back(keyword);
- }
- std::list<MediaBase*>* MediaBase::GetChildList()
- {
- return m_ChildList;
- };
- int MediaBase::GetMediaType()
- {
- return m_Type;
- }
- MediaBase* MediaBase::GetMediaByName(char* name)
- {
- MediaBase* result = NULL;
- if ((this->m_MediaName == NULL && name == NULL) || (strcmp(this->m_MediaName, name) == 0))
- {
- return this;
- }
- else
- {
- if (m_ChildList != NULL)
- {
- for(list<MediaBase*>::iterator i = m_ChildList->begin(); i != m_ChildList->end(); i++)
- {
- MediaBase* child = *i;
- result = child->GetMediaByName(name);
- if (result != NULL)
- return result;
- }
- }
- else
- {
- return NULL;
- }
- }
- return result;
- }
- void MediaBase::PrintMedia()
- {
- for (int i = 0; i < m_Type; i++)
- {
- cout << " ";
- }
- cout << m_MediaName << endl;
- if (m_KeywordList != NULL)
- {
- int count = (int)m_KeywordList->size();
- for(list<char*>::iterator i = m_KeywordList->begin(); i != m_KeywordList->end(); i++)
- {
- char* keyword = *i;
- for (int j = 0; j < m_Type; j++)
- {
- cout << " ";
- }
- cout << " ";
- cout << keyword << endl;
- }
- }
- if (m_ChildList != NULL)
- {
- for(list<MediaBase*>::iterator i = m_ChildList->begin(); i != m_ChildList->end(); i++)
- {
- MediaBase* child = *i;
- child->PrintMedia();
- }
- }
- }