本文整理汇总了C++中FileSource类的典型用法代码示例。如果您正苦于以下问题:C++ FileSource类的具体用法?C++ FileSource怎么用?C++ FileSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onFrameSelected
/******************************************************************************
* Is called when the user has selected a certain frame in the frame list box.
******************************************************************************/
void FileSourceEditor::onFrameSelected(int index)
{
FileSource* obj = static_object_cast<FileSource>(editObject());
if(!obj) return;
dataset()->animationSettings()->setTime(obj->inputFrameToAnimationTime(index));
}
示例2: parsed
GlyphPBF::GlyphPBF(GlyphStore* store,
const std::string& fontStack,
const GlyphRange& glyphRange,
GlyphStore::Observer* observer_)
: parsed(false),
observer(observer_) {
// Load the glyph set URL
std::string url = util::replaceTokens(store->getURL(), [&](const std::string &name) -> std::string {
if (name == "fontstack") return util::percentEncode(fontStack);
if (name == "range") return util::toString(glyphRange.first) + "-" + util::toString(glyphRange.second);
return "";
});
auto requestCallback = [this, store, fontStack, glyphRange](Response res) {
if (res.error) {
observer->onGlyphsError(fontStack, glyphRange, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (data != res.data || (*data != *res.data)) {
data = res.data;
parse(store, fontStack, glyphRange);
}
};
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Glyphs, url }, requestCallback);
}
示例3: parsed
GlyphPBF::GlyphPBF(GlyphStore* store,
const std::string& fontStack,
const GlyphRange& glyphRange)
: parsed(false) {
// Load the glyph set URL
std::string url = util::replaceTokens(store->getURL(), [&](const std::string &name) -> std::string {
if (name == "fontstack") return util::percentEncode(fontStack);
if (name == "range") return util::toString(glyphRange.first) + "-" + util::toString(glyphRange.second);
return "";
});
auto requestCallback = [this, store, fontStack, url](const Response &res) {
if (res.stale) {
// Only handle fresh responses.
return;
}
req = nullptr;
if (res.error) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.error->message;
emitGlyphPBFLoadingFailed(message.str());
} else {
data = res.data;
parse(store, fontStack, url);
}
};
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Glyphs, url }, util::RunLoop::getLoop(), requestCallback);
}
示例4: request
void VectorTileData::request(float pixelRatio, const std::function<void()>& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::getLoop(), [url, callback, this](const Response &res) {
req = nullptr;
if (res.status == Response::NotFound) {
state = State::parsed;
callback();
return;
}
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
error = message.str();
state = State::obsolete;
callback();
return;
}
state = State::loaded;
data = res.data;
reparse(callback);
});
}
示例5: setStyleURL
void MapContext::setStyleURL(const std::string& url) {
FileSource* fs = util::ThreadContext::getFileSource();
if (styleRequest) {
fs->cancel(styleRequest);
}
styleURL = url;
styleJSON.clear();
style = std::make_unique<Style>(data, asyncUpdate->get()->loop);
const size_t pos = styleURL.rfind('/');
std::string base = "";
if (pos != std::string::npos) {
base = styleURL.substr(0, pos + 1);
}
styleRequest = fs->request({ Resource::Kind::Style, styleURL }, util::RunLoop::getLoop(), [this, base](const Response &res) {
styleRequest = nullptr;
if (res.status == Response::Successful) {
loadStyleJSON(res.data, base);
} else {
Log::Error(Event::Setup, "loading style failed: %s", res.message.c_str());
}
});
}
示例6: assert
void
TapeComposition::addSampleInstance( const smp::SampleInstance &sampleInstance )
{
// don't create anther if it exists.
#ifndef NDEBUG
for ( SampleInstanceList::const_iterator it = m_samples.begin(); it != m_samples.end(); ++ it )
assert( &sampleInstance != it->first );
#endif
// Create a Filesource
FileSource *source = new FileSource;
if ( !gst_bin_add( GST_BIN( m_selfElement ), source->m_element ) )
{
// If there was an error, clean up safely
delete source;
}
else
{
const smp::Sample *sample = &sampleInstance.getSample();
// TODO not needed; do this in update()
source->setFilename( sample->getFilename() );
source->setStart( sample->getStart() );
source->setDuration( sample->getDuration() );
// Keep a pointer
m_samples.push_back( SampleInstancePair( &sampleInstance, source ) );
}
}
示例7: onReloadFrame
/******************************************************************************
* Is called when the user presses the Reload frame button.
******************************************************************************/
void FileSourceEditor::onReloadFrame()
{
FileSource* obj = static_object_cast<FileSource>(editObject());
if(obj) {
obj->refreshFromSource(obj->loadedFrameIndex());
obj->notifyDependents(ReferenceEvent::TargetChanged);
}
}
示例8: request
void RasterTileData::request(float pixelRatio,
const std::function<void()>& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::getLoop(), [url, callback, this](const Response &res) {
if (res.stale) {
// Only handle fresh responses.
return;
}
req = nullptr;
if (res.status == Response::NotFound) {
state = State::parsed;
callback();
return;
}
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
error = message.str();
state = State::obsolete;
callback();
return;
}
if (state == State::loading) {
// Only overwrite the state when we didn't have a previous tile.
state = State::loaded;
}
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool, layout), res.data, [this, callback] (TileParseResult result) {
workRequest.reset();
if (state != State::loaded) {
return;
}
if (result.is<TileParseResultBuckets>()) {
auto& buckets = result.get<TileParseResultBuckets>();
state = buckets.state;
// TODO: Make this less awkward; we're only getting one bucket back.
if (!buckets.buckets.empty()) {
bucket = std::move(buckets.buckets.front().second);
}
} else {
std::stringstream message;
message << "Failed to parse [" << std::string(id) << "]: " << result.get<std::string>();
error = message.str();
state = State::obsolete;
}
callback();
});
});
}
示例9: FileSource
SoundSource *SoundEngineOpenAL::getSourcePCM(std::string filename,
const SoundFormat &format)
{
FileSource *source = new FileSource();
if (!source->open(filename))
{
delete source;
return 0;
}
return getSourcePCM(filename, source, format);
}
示例10: request
void RasterTileData::request(float pixelRatio,
const RasterTileData::Callback& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Tile, url }, [url, callback, this](Response res) {
if (res.stale) {
// Only handle fresh responses.
return;
}
req = nullptr;
if (res.error) {
if (res.error->reason == Response::Error::Reason::NotFound) {
state = State::parsed;
} else {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.error->message;
error = message.str();
state = State::obsolete;
}
callback();
return;
}
if (state == State::loading) {
// Only overwrite the state when we didn't have a previous tile.
state = State::loaded;
}
modified = res.modified;
expires = res.expires;
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool), res.data, [this, callback] (RasterTileParseResult result) {
workRequest.reset();
if (state != State::loaded) {
return;
}
if (result.is<std::unique_ptr<Bucket>>()) {
state = State::parsed;
bucket = std::move(result.get<std::unique_ptr<Bucket>>());
} else {
std::stringstream message;
message << "Failed to parse [" << std::string(id) << "]: " << result.get<std::string>();
error = message.str();
state = State::obsolete;
}
callback();
});
});
}
示例11: spriteURL
void SpriteStore::setURL(const std::string& url) {
if (url.empty()) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
loaded = true;
return;
}
std::string spriteURL(url + (pixelRatio > 1 ? "@2x" : "") + ".png");
std::string jsonURL(url + (pixelRatio > 1 ? "@2x" : "") + ".json");
loader = std::make_unique<Loader>();
FileSource* fs = util::ThreadContext::getFileSource();
loader->jsonRequest = fs->request({ Resource::Kind::SpriteJSON, jsonURL }, util::RunLoop::getLoop(),
[this, jsonURL](const Response& res) {
if (res.stale) {
// Only handle fresh responses.
return;
}
loader->jsonRequest = nullptr;
if (res.error) {
std::stringstream message;
message << "Failed to load [" << jsonURL << "]: " << res.error->message;
emitSpriteLoadingFailed(message.str());
return;
} else {
loader->json = res.data;
}
emitSpriteLoadedIfComplete();
});
loader->spriteRequest =
fs->request({ Resource::Kind::SpriteImage, spriteURL }, util::RunLoop::getLoop(),
[this, spriteURL](const Response& res) {
if (res.stale) {
// Only handle fresh responses.
return;
}
loader->spriteRequest = nullptr;
if (res.error) {
std::stringstream message;
message << "Failed to load [" << spriteURL << "]: " << res.error->message;
emitSpriteLoadingFailed(message.str());
return;
} else {
loader->image = res.data;
}
emitSpriteLoadedIfComplete();
});
}
示例12: onReloadAnimation
/******************************************************************************
* Is called when the user presses the Reload animation button.
******************************************************************************/
void FileSourceEditor::onReloadAnimation()
{
FileSource* obj = static_object_cast<FileSource>(editObject());
OVITO_CHECK_OBJECT_POINTER(obj);
try {
obj->updateFrames();
}
catch(const Exception& ex) {
ex.showError();
}
// Adjust the animation length number to match the number of frames in the input data source.
obj->adjustAnimationInterval();
}
示例13:
WaveFileModel::WaveFileModel(FileSource source, size_t targetRate) :
m_source(source),
m_path(source.getLocation()),
m_myReader(true),
m_startFrame(0),
m_fillThread(0),
m_updateTimer(0),
m_lastFillExtent(0),
m_exiting(false),
m_lastDirectReadStart(0),
m_lastDirectReadCount(0)
{
m_source.waitForData();
if (m_source.isOK()) {
m_reader = AudioFileReaderFactory::createThreadingReader
(m_source, targetRate);
if (m_reader) {
SVDEBUG << "WaveFileModel::WaveFileModel: reader rate: "
<< m_reader->getSampleRate() << endl;
}
}
if (m_reader) setObjectName(m_reader->getTitle());
if (objectName() == "") setObjectName(QFileInfo(m_path).fileName());
if (isOK()) fillCache();
}
示例14: OpenDataFile
Source<char> *
OpenDataFile(const TCHAR *name, Error &error)
{
assert(name != nullptr);
assert(!StringIsEmpty(name));
const auto path = LocalPath(name);
FileSource *source = new FileSource(path, error);
if (source->error()) {
delete source;
return nullptr;
}
return source;
}
示例15: load
// Note: This is a separate function that must be called exactly once after creation
// The reason this isn't part of the constructor is that calling shared_from_this() in
// the constructor fails.
void Source::load(Map& map, FileSource& fileSource) {
if (info.url.empty()) {
loaded = true;
return;
}
std::string url = util::mapbox::normalizeSourceURL(info.url, map.getAccessToken());
util::ptr<Source> source = shared_from_this();
fileSource.request(ResourceType::JSON, url)->onload([source, &map](const Response &res) {
if (res.code != 200) {
Log::Warning(Event::General, "failed to load source TileJSON");
return;
}
rapidjson::Document d;
d.Parse<0>(res.data.c_str());
if (d.HasParseError()) {
Log::Warning(Event::General, "invalid source TileJSON");
return;
}
source->info.parseTileJSONProperties(d);
source->loaded = true;
map.update();
});
}