這是我寫的一個班級模板。它有兩個公共功能(三個如果你計算Instance()
;它是一個單身人士)和四個私人功能。代碼不太重要;我想問問你是否認爲我的文檔評論過於明確。我的文檔評論是否過於冗長?
我試圖記錄當輸入錯誤等情況時會發生什麼,並且準確地說明了所有內容,但是我見過的其他庫沒有這樣的顯式文檔—我是否過度使用它?
/**
\class ResourceManager
\details Singleton class template used for ensuring resources do not get
loaded into memory more than once at any given time. Types (classes) used
as template parameters must implement the IResource interface.
\see IResource
\todo Add messages to the Logger if the creation of a new resource
fails. The documentation of pushNewResource() and acquire() will have
to be updated.
*/
template<class T>
class ResourceManager
{
public:
static ResourceManager<T>* Instance();
/**
\fn acquire
\details Function used for accessing resource. It loads the resource
or returns the already loaded resource, depending on whether or not
it has been previously loaded into memory. A null pointer is returned
on failure.
\param file Path to the file to be loaded. An invalid path will
result in a null pointer being returned.
\return Pointer to the resource or null pointer on failure.
\note The resource should be released through the release() function
when no longer required.
*/
T* acquire(const std::string& file);
/**
\fn release
\details Checks to see if the resource is loaded in memory. If it is,
it determines whether it is still in use and if not it deletes it.
\param ptr Pointer to the object to release. Null pointers or
pointers to non-existent objects will not produce any errors.
*/
void release(T* ptr);
protected:
ResourceManager();
ResourceManager(const ResourceManager<T>& other);
ResourceManager<T>& operator=(const ResourceManager<T>& other);
~ResourceManager();
private:
struct ResourceWrapper;
std::list<ResourceWrapper*> resources_;
/**
\fn searchForResource(const std::string&)
\details Searches the list of resources for one whose source file
path matches the given string.
\param file String of the path to the source file. Invalid paths
will not produce any errors.
\return Returns std::list<>::iterator to the found resource or the
std::list<>::end() iterator if nothing found.
*/
typename std::list<ResourceWrapper*>::iterator
searchForResource(const std::string& file);
/**
\fn serachForResource(const T*)
\details Seraches the list of resources for one whose pointer
matches the parameter.
\param ptr Pointer to the object to find. Null pointers or
pointers of non-existent objects will not produce any errors.
\return Returns std::list<>::iterator to the found resource or the
std::list<>::end() iterator if nothing found.
*/
typename std::list<ResourceWrapper*>::iterator
searchForResource(const T* ptr);
/**
\fn pushNewResource
\details Attempts to create a new reosurce corresponding to the
given file path and push it to the resources list.
\param file String containing the path to the resource file. Incorrect
paths or paths to incorrect files will result in the std::list<>::end()
iterator being returned.
\return Returns std::list<>::iterator to newly added reosurce or the
std::list<>::end() iterator if the resource could not be created.
*/
typename std::list<ResourceWrapper*>::iterator
pushNewResource(const std::string& file);
/**
\fn deleteResource
\details Removes the resource corresponding to the given iterator
from the resources list. No check is done to ensure the iterator is
valid or to ensure the resource is no longer in use.
\param it An std::list<>::iterator pointing to the resource to be
deleted. Validity of the iterator is not checked.
\note The iterator is best acquired through the searchForResource()
private member function.
*/
void deleteResource(typename std::list<ResourceWrapper*>::iterator it);
};
我同意,簡明絕對是要爭取的東西,但我仍然會使用正確的語法。也許你只是給了一個不好的例子(或者你可能遺漏了一些單詞),但是'用於記憶中的一個實例的模板'對我來說沒有多大意義。 :) – 2011-04-19 10:25:03
嗯,這沒什麼意義......關於正確的語法,是的......但我不認爲你需要完整的句子 無論如何,我會編輯我的那句話,因爲我似乎忘記了一個詞 – Holger 2011-04-19 11:28:26