这是我写的一个班级模板。它有两个公共功能(三个如果你计算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