我为脱机(例如)单页HTML应用程序的IndexDB并置而感到困惑,因为该文档似乎表明浏览器可以随时破坏本地数据。“此外,请注意浏览器可以清除数据库,例如在以下情况下:”
似乎可以选择以下选项:a)仅设计只读的脱机应用程序,或b)偶尔接受您的脱机应用程序的某些用户在浏览器有意删除时会很不幸并失去所有工作您的IndexedDB数据。
我的问题是:是否在任何地方都对此问题进行了认真的讨论,或者(一个更好的方案,但希望太多)一个严肃的可读写脱机应用程序来处理该问题?我对该主题的搜索毫无结果。例如,这个完整的离线待办事项应用示例设法解决了这个问题-谁想将甚至简单的待办事项数据存储在浏览器随时可能消失且无法轻松备份的存储中?
我有这样的安排:
class LexedFile
{
friend class Lex;
//...
private:
~LexedFile();
};
class Lex
{
//...
private:
std::map<std::string, std::unique_ptr<LexedFile> > Files;
};
Run Code Online (Sandbox Code Playgroud)
Lex 是LexedFile
对象的唯一创建者,并保留LexedFile
其在映射中创建的所有对象的所有权。不幸的是,由于从映射变量到LexedFile
析构函数的可见性规则,编译器强烈抱怨这一点。我可以通过公开来解决这个问题~LexedFile()
,但是当然,我将其设为私有的原因是为了强化该类型的对象仅属于Lex
对象的决定。
我的问题是:我有哪些便携式选项可以让我unique_ptr
开心并保持~LexedFile()
私密性?对于可移植性,我想它至少必须与最新的 g++ 和最新的 Visual C++ 一起工作。
我尝试插入类似的内容:
friend class std::unique_ptr<LexedFile>;
Run Code Online (Sandbox Code Playgroud)
但即使它有效(它没有),它似乎依赖于关于可能不可移植的实现的假设。
我已经开始使用C++ 11,特别是使用unique_ptr来使代码异常安全且所有权更具可读性.这通常很有效,直到我想抛出unique_ptr.我有错误代码(抛出许多地方,陷入一个地方),创建复杂的状态.由于逻辑上动态分配的内存的所有权正从thrower传递到catcher,所以unique_ptr似乎是适当的类型来表示并明确catcher已经获得了一个堆对象.没有工作,至少使用免费的Visual Studio 2013.这是一个简化的代码示例,它不再像任何有用的东西,但会引发行为:
// cl /nologo /EHsc /W4 test1.cpp
#include <memory>
using std::unique_ptr;
class IError
{
public:
virtual ~IError() {};
virtual void DoStuff();
};
unique_ptr<IError> Error();
int Foo() { throw Error(); }
int main(void)
{
try {
Foo();
}
catch(unique_ptr<IError> Report)
{
Report->DoStuff();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并且编译器如此喷出:
test1.cpp
test1.cpp(13) : warning C4673: throwing 'std::unique_ptr<IError,std::default_delete<_Ty>>' the following types will n
ot be considered at the catch site
with
[
_Ty=IError
]
test1.cpp(13) : warning C4670: '_Unique_ptr_base<class IError,struct std::default_delete<class IError>,1>' …
Run Code Online (Sandbox Code Playgroud) c++ ×2
unique-ptr ×2
destructor ×1
dictionary ×1
friend ×1
html5 ×1
indexeddb ×1
javascript ×1
offlineapps ×1
stl ×1