WriteStructContext treats state of fs

This commit is contained in:
Koji Miyazato 2014-03-18 23:29:30 +09:00
parent b96762a48f
commit a43ef9a6cd
2 changed files with 18 additions and 2 deletions

View File

@ -697,9 +697,8 @@ void write(FileStorage& fs, const String& name, const Range& r )
template<typename _Tp> static inline
void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec )
{
fs << (DataType<_Tp>::fmt != 0 ? "[:" : "[");
internal::WriteStructContext ws(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0));
write(fs, vec);
fs << "]";
}
static inline

View File

@ -5486,11 +5486,28 @@ internal::WriteStructContext::WriteStructContext(FileStorage& _fs,
{
cvStartWriteStruct(**fs, !name.empty() ? name.c_str() : 0, flags,
!typeName.empty() ? typeName.c_str() : 0);
if ((flags & FileNode::TYPE_MASK) == FileNode::SEQ)
{
fs->elname = String();
fs->state = FileStorage::VALUE_EXPECTED;
fs->structs.push_back('[');
}
else
{
fs->elname = String();
fs->state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP;
fs->structs.push_back('{');
}
}
internal::WriteStructContext::~WriteStructContext()
{
cvEndWriteStruct(**fs);
fs->structs.pop_back();
fs->state = fs->structs.empty() || fs->structs.back() == '{' ?
FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP :
FileStorage::VALUE_EXPECTED;
fs->elname = String();
}