mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 19:10:20 +01:00
synchronized trunk
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// DynamicAny.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/DynamicAny.cpp#4 $
|
||||
// $Id: //poco/Main/Foundation/src/DynamicAny.cpp#5 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -35,7 +35,9 @@
|
||||
|
||||
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -75,7 +77,187 @@ void DynamicAny::swap(DynamicAny& ptr)
|
||||
|
||||
const std::type_info& DynamicAny::type() const
|
||||
{
|
||||
return _pHolder->type();
|
||||
return _pHolder->type();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n)
|
||||
{
|
||||
DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder = dynamic_cast<DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](n);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder = dynamic_cast<const DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](n);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator[](const std::string& name)
|
||||
{
|
||||
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator[](const std::string& name) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
||||
if (pHolder)
|
||||
return pHolder->operator[](name);
|
||||
else
|
||||
throw BadCastException();
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val)
|
||||
{
|
||||
std::string::size_type t = 0;
|
||||
return parse(val, t);
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parse(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
// { -> an Object==DynamicStruct
|
||||
// [ -> an array
|
||||
// '/" -> a string (strip '/")
|
||||
// other: also treat as string
|
||||
skipWhiteSpace(val, pos);
|
||||
if (pos < val.size())
|
||||
{
|
||||
switch(val[pos])
|
||||
{
|
||||
case '{':
|
||||
return parseObject(val, pos);
|
||||
case '[':
|
||||
return parseArray(val, pos);
|
||||
default:
|
||||
return parseString(val, pos);
|
||||
}
|
||||
}
|
||||
std::string empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseObject(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '{');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
DynamicStruct aStruct;
|
||||
while(val[pos] != '}' && pos < val.size())
|
||||
{
|
||||
std::string key = parseString(val, pos);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] != ':')
|
||||
throw DataFormatException("Incorrect object, must contain: key : value pairs");
|
||||
++pos; // skip past :
|
||||
DynamicAny value = parse(val, pos);
|
||||
aStruct.insert(key, value);
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != '}')
|
||||
throw DataFormatException("Unterminated object");
|
||||
++pos;
|
||||
return aStruct;
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::parseArray(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
poco_assert_dbg (val[pos] == '[');
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
std::vector<DynamicAny> result;
|
||||
while(val[pos] != ']' && pos < val.size())
|
||||
{
|
||||
result.push_back(parse(val, pos));
|
||||
skipWhiteSpace(val, pos);
|
||||
if (val[pos] == ',')
|
||||
{
|
||||
++pos;
|
||||
skipWhiteSpace(val, pos);
|
||||
}
|
||||
}
|
||||
if (val[pos] != ']')
|
||||
throw DataFormatException("Unterminated array");
|
||||
++pos;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::parseString(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
static const std::string STR_STOP("'\"");
|
||||
static const std::string OTHER_STOP(" ,]}"); // we stop at space, ',', ']' or '}'
|
||||
|
||||
bool inString = false;
|
||||
//skip optional ' "
|
||||
if (val[pos] == '\'' || val[pos] == '"')
|
||||
{
|
||||
inString = true;
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
std::string::size_type stop = std::string::npos;
|
||||
if (inString)
|
||||
{
|
||||
stop = val.find_first_of(STR_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
throw DataFormatException("Unterminated string");
|
||||
}
|
||||
else
|
||||
{
|
||||
// we stop at space, ',', ']' or '}' or end of string
|
||||
stop = val.find_first_of(OTHER_STOP, pos);
|
||||
if (stop == std::string::npos)
|
||||
stop = val.size();
|
||||
|
||||
std::string::size_type safeCheck = val.find_first_of(STR_STOP, pos);
|
||||
if (safeCheck != std::string::npos && safeCheck < stop)
|
||||
throw DataFormatException("Misplaced string termination char found");
|
||||
|
||||
}
|
||||
|
||||
// stop now points to the last char to be not included
|
||||
std::string result = val.substr(pos, stop - pos);
|
||||
++stop; // point past '/"
|
||||
pos = stop;
|
||||
return result;
|
||||
}
|
||||
|
||||
void DynamicAny::skipWhiteSpace(const std::string& val, std::string::size_type& pos)
|
||||
{
|
||||
while (std::isspace(val[pos]))
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
std::string DynamicAny::toString(const DynamicAny& any)
|
||||
{
|
||||
std::string res;
|
||||
appendJSONString(res, any);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// DynamicAnyHolder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/DynamicAnyHolder.cpp#2 $
|
||||
// $Id: //poco/Main/Foundation/src/DynamicAnyHolder.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
|
||||
#include "Poco/DynamicAnyHolder.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -50,4 +51,18 @@ DynamicAnyHolder::~DynamicAnyHolder()
|
||||
}
|
||||
|
||||
|
||||
void appendJSONString(std::string& val, const DynamicAny& any)
|
||||
{
|
||||
bool isJsonString = (any.type() == typeid(std::string) || any.type() == typeid(char) || any.type() == typeid(Poco::DateTime) || any.type() == typeid(Poco::LocalDateTime));
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
val.append(any.convert<std::string>());
|
||||
if (isJsonString)
|
||||
{
|
||||
val.append(1, '\'');
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
81
Foundation/src/DynamicStruct.cpp
Normal file
81
Foundation/src/DynamicStruct.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// DynamicStruct.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/DynamicStruct.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: DynamicStruct
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DynamicStruct.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct():
|
||||
_data()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::DynamicStruct(const Data& d):
|
||||
_data(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicStruct::~DynamicStruct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicStruct::operator[](const std::string& name) const
|
||||
{
|
||||
ConstIterator it = find(name);
|
||||
if (it == end())
|
||||
throw NotFoundException(name);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
std::set<std::string> DynamicStruct::members() const
|
||||
{
|
||||
std::set<std::string> keys;
|
||||
ConstIterator it = begin();
|
||||
ConstIterator itEnd = end();
|
||||
for (; it != itEnd; ++it)
|
||||
keys.insert(it->first);
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco::Poco
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Glob.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/Glob.cpp#6 $
|
||||
// $Id: //poco/Main/Foundation/src/Glob.cpp#7 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -219,7 +219,7 @@ void Glob::collect(const Path& pathPattern, const Path& base, const Path& curren
|
||||
else
|
||||
{
|
||||
p.setFileName(name);
|
||||
if (File(p).isDirectory())
|
||||
if (isDirectory(p, (options & GLOB_FOLLOW_SYMLINKS) != 0))
|
||||
{
|
||||
p.makeDirectory();
|
||||
files.insert(p.toString());
|
||||
@@ -239,4 +239,27 @@ void Glob::collect(const Path& pathPattern, const Path& base, const Path& curren
|
||||
}
|
||||
|
||||
|
||||
bool Glob::isDirectory(const Path& path, bool followSymlink)
|
||||
{
|
||||
File f(path);
|
||||
if (f.isDirectory())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (followSymlink && f.isLink())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Test if link resolves to a directory.
|
||||
DirectoryIterator it(f);
|
||||
return true;
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MemoryPool.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/MemoryPool.cpp#6 $
|
||||
// $Id: //poco/Main/Foundation/src/MemoryPool.cpp#7 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -47,6 +47,7 @@ MemoryPool::MemoryPool(std::size_t blockSize, int preAlloc, int maxAlloc):
|
||||
_allocated(preAlloc)
|
||||
{
|
||||
poco_assert (maxAlloc == 0 || maxAlloc >= preAlloc);
|
||||
poco_assert (preAlloc >= 0 && maxAlloc >= 0);
|
||||
|
||||
int r = BLOCK_RESERVE;
|
||||
if (preAlloc > r)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SharedMemory.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory.cpp#6 $
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory.cpp#7 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
@@ -60,8 +60,8 @@ SharedMemory::SharedMemory():
|
||||
}
|
||||
|
||||
|
||||
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint):
|
||||
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint))
|
||||
SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
|
||||
_pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_DUMMY.cpp#3 $
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_DUMMY.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
@@ -40,7 +40,7 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*)
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string&, std::size_t, SharedMemory::AccessMode, const void*, bool)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_POSIX.cpp#9 $
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_POSIX.cpp#10 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
@@ -47,13 +47,14 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint):
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void* addrHint, bool server):
|
||||
_size(size),
|
||||
_fd(-1),
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name("/"),
|
||||
_fileMapped(false)
|
||||
_fileMapped(false),
|
||||
_server(server)
|
||||
{
|
||||
#if POCO_OS == POCO_OS_HPUX
|
||||
_name.append("tmp/");
|
||||
@@ -90,7 +91,8 @@ SharedMemoryImpl::SharedMemoryImpl(const Poco::File& file, SharedMemory::AccessM
|
||||
_address(0),
|
||||
_access(mode),
|
||||
_name(file.path()),
|
||||
_fileMapped(true)
|
||||
_fileMapped(true),
|
||||
_server(false)
|
||||
{
|
||||
if (!file.exists() || !file.isFile())
|
||||
throw FileNotFoundException(file.path());
|
||||
@@ -144,7 +146,7 @@ void SharedMemoryImpl::close()
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
if (!_fileMapped)
|
||||
if (!_fileMapped && _server)
|
||||
{
|
||||
::shm_unlink(_name.c_str());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SharedMemoryImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_WIN32.cpp#6 $
|
||||
// $Id: //poco/Main/Foundation/src/SharedMemory_WIN32.cpp#7 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
@@ -46,7 +46,7 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*):
|
||||
SharedMemoryImpl::SharedMemoryImpl(const std::string& name, std::size_t size, SharedMemory::AccessMode mode, const void*, bool):
|
||||
_name(name),
|
||||
_memHandle(INVALID_HANDLE_VALUE),
|
||||
_fileHandle(INVALID_HANDLE_VALUE),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// UUIDGenerator.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/UUIDGenerator.cpp#18 $
|
||||
// $Id: //poco/Main/Foundation/src/UUIDGenerator.cpp#19 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: UUID
|
||||
@@ -202,6 +202,7 @@ void UUIDGenerator::getNode()
|
||||
std::memcpy(_node, pAdapter->Address, pAdapter->AddressLength);
|
||||
found = true;
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
else throw SystemException("cannot get network adapter list");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// pocomsg.mc[.h]
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/pocomsg.h#26 $
|
||||
// $Id: //poco/Main/Foundation/src/pocomsg.mc#7 $
|
||||
//
|
||||
// The Poco message source/header file.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user