25 #include "usAtomicInt_p.h"
26 #include "usModuleResourceContainer_p.h"
33 class ModuleResourcePrivate
38 ModuleResourcePrivate(
const ModuleResourceContainer* rc)
39 : resourceContainer(rc)
43 void InitFilePath(
const std::string& file);
45 const ModuleResourceContainer*
const resourceContainer;
47 ModuleResourceContainer::Stat stat;
52 mutable std::vector<std::string> children;
53 mutable std::vector<uint32_t> childNodes;
61 void ModuleResourcePrivate::InitFilePath(
const std::string& file)
63 std::string normalizedFile = file;
64 if (normalizedFile.empty() || normalizedFile[0] !=
'/')
66 normalizedFile =
'/' + normalizedFile;
70 std::size_t index = normalizedFile.find_last_of(
'/');
71 if (index == std::string::npos)
73 fileName = normalizedFile;
75 else if (index < normalizedFile.size()-1)
77 fileName = normalizedFile.substr(index+1);
78 rawPath = normalizedFile.substr(0,index+1);
82 rawPath = normalizedFile;
86 std::string::value_type lastChar = 0;
87 for (std::size_t i = 0; i < rawPath.size(); ++i)
89 if (rawPath[i] ==
'/' && lastChar ==
'/')
93 lastChar = rawPath[i];
94 path.push_back(lastChar);
102 ModuleResource::ModuleResource()
103 : d(new ModuleResourcePrivate(NULL))
114 : d(new ModuleResourcePrivate(&resourceContainer))
116 d->InitFilePath(file);
118 d->stat.filePath = d->resourceContainer->GetModuleInfo()->name + d->path + d->fileName;
120 d->resourceContainer->GetStat(d->stat);
124 : d(new ModuleResourcePrivate(&resourceContainer))
126 d->resourceContainer->GetStat(index, d->stat);
127 d->InitFilePath(d->stat.filePath.substr(d->resourceContainer->GetModuleInfo()->name.size()));
138 ModuleResourcePrivate* curr_d = d;
142 if (!curr_d->ref.Deref())
155 return d->resourceContainer == resource.d->resourceContainer &&
161 return !(*
this == resource);
166 return d->resourceContainer && d->resourceContainer->IsValid() && d->stat.index > -1;
169 ModuleResource::operator bool_type()
const
171 return IsValid() ? &ModuleResource::d : NULL;
186 return d->path + d->fileName;
191 return d->fileName.substr(0, d->fileName.find_first_of(
'.'));
196 return d->fileName.substr(0, d->fileName.find_last_of(
'.'));
201 std::size_t index = d->fileName.find_last_of(
'.');
202 return index < d->fileName.size()-1 ? d->fileName.substr(index+1) : std::string(
"");
207 std::size_t index = d->fileName.find_first_of(
'.');
208 return index < d->fileName.size()-1 ? d->fileName.substr(index+1) : std::string(
"");
213 return d->stat.isDir;
218 return !d->stat.isDir;
225 if (d->children.empty())
227 d->resourceContainer->GetChildren(d->stat.filePath,
true,
228 d->children, d->childNodes);
235 std::vector<ModuleResource> childResources;
239 if (d->childNodes.empty())
242 d->children, d->childNodes);
245 for (std::vector<uint32_t>::const_iterator iter = d->childNodes.begin(),
246 iterEnd = d->childNodes.end(); iter != iterEnd; ++iter)
248 childResources.push_back(
ModuleResource(static_cast<int>(*iter), *d->resourceContainer));
250 return childResources;
255 return d->stat.uncompressedSize;
260 return d->stat.modifiedTime;
263 std::size_t ModuleResource::Hash()
const
265 using namespace US_HASH_FUNCTION_NAMESPACE;
269 void* ModuleResource::GetData()
const
273 void* data = d->resourceContainer->GetData(d->stat.index);
276 US_WARN <<
"Error uncompressing resource data for " << this->
GetResourcePath() <<
" from "
277 << d->resourceContainer->GetModuleInfo()->location;
288 return os << resource.GetResourcePath();
ModuleResource & operator=(const ModuleResource &resource)
std::string GetResourcePath() const
std::vector< ModuleResource > GetChildResources() const
std::string GetName() const
bool operator==(const ModuleResource &resource) const
bool operator<(const ModuleResource &resource) const
time_t GetLastModified() const
bool operator!=(const ModuleResource &resource) const
std::string GetPath() const
std::string GetCompleteBaseName() const
US_Core_EXPORT std::ostream & operator<<(std::ostream &os, ModuleEvent::Type eventType)
std::vector< std::string > GetChildren() const
std::string GetSuffix() const
std::string GetCompleteSuffix() const
US_MSVC_POP_WARNING US_HASH_FUNCTION_NAMESPACE_BEGIN return US_HASH_FUNCTION(us::ServiceRegistrationBasePrivate *, arg.d)
std::string GetBaseName() const