From 464de381a088f820167f12249aec0f54a3c7b266 Mon Sep 17 00:00:00 2001 From: Paulchen Panther Date: Thu, 13 Oct 2016 21:59:58 +0200 Subject: [PATCH] JsonCpp to QTJson (Final Part) (#273) * Update CMakeLists.txt * Update Hyperion.h * Update LedDevice.h * Update LedDeviceFactory.h * Update Hyperion.cpp * Update LedString.cpp * Update JsonClientConnection.cpp * Update LedDeviceAdalight.cpp * Update LedDeviceAdalight.h * Update LedDeviceAPA102.cpp * Update LedDeviceAdalightApa102.h * Update LedDeviceAdalightApa102.cpp * Update LedDeviceAPA102.h * Update LedDeviceAtmo.cpp * Update LedDeviceAtmo.h * Update LedDeviceAtmoOrb.cpp * Update LedDeviceAtmoOrb.h * Update LedDeviceDMX.cpp * Update LedDeviceDMX.h * Update LedDeviceFactory.cpp * Update LedDeviceFadeCandy.cpp * Update LedDeviceFadeCandy.h * Update LedDeviceFile.cpp * Update LedDeviceFile.h * Update LedDeviceHyperionUsbasp.cpp * Update LedDeviceHyperionUsbasp.h * Update LedDeviceLightpack.cpp * Update LedDeviceLightpack.h * Update LedDeviceLpd6803.cpp * Update LedDeviceLpd6803.h * Update LedDeviceLpd8806.cpp * Update LedDeviceLpd8806.h * Update LedDeviceMultiLightpack.cpp * Update LedDeviceMultiLightpack.h * Update LedDeviceP9813.cpp * Update LedDeviceP9813.h * Update LedDevicePaintpack.cpp * Update LedDevicePaintpack.h * Update LedDevicePhilipsHue.cpp * Update LedDevicePhilipsHue.h * Update LedDevicePiBlaster.cpp * Update LedDevicePiBlaster.h * Update LedDeviceRawHID.cpp * Update LedDeviceRawHID.h * Update LedDeviceSedu.cpp * Update LedDeviceSedu.h * Update LedDeviceSk6812SPI.cpp * Update LedDeviceSk6812SPI.h * Update LedDeviceTinkerforge.cpp * Update LedDeviceTinkerforge.h * Update LedDeviceTpm2.cpp * Update LedDeviceTpm2.h * Update LedDeviceTpm2net.cpp * Update LedDeviceTpm2net.h * Update LedDeviceUdpE131.cpp * Update LedDeviceUdpE131.h * Update LedDeviceUdpH801.cpp * Update LedDeviceUdpH801.h * Update LedDeviceUdpRaw.cpp * Update LedDeviceUdpRaw.h * Update LedDeviceWs2801.cpp * Update LedDeviceWs2801.h * Update LedDeviceWS2812b.cpp * Update LedDeviceWS2812b.h * Update LedDeviceWs2812SPI.cpp * Update LedDeviceWs2812SPI.h * Update LedDeviceWS281x.cpp * Update LedDeviceWS281x.h * Update ProviderHID.cpp * Update ProviderHID.h * Update ProviderRs232.cpp * Update ProviderRs232.h * Update ProviderSpi.cpp * Update ProviderSpi.h * Update ProviderUdp.cpp * Update ProviderUdp.h * Update LedDevice.cpp * Update CMakeLists.txt * Update hyperiond.cpp * Update hyperiond.h * Update TestSpi.cpp * Delete AUTHORS * Delete CMakeLists.txt * Delete LICENSE * Delete json_batchallocator.h * Delete json_internalarray.inl * Delete json_internalmap.inl * Delete json_reader.cpp * Delete json_tool.h * Delete json_value.cpp * Delete json_valueiterator.inl * Delete json_writer.cpp * Delete sconscript * Delete autolink.h * Delete config.h * Delete features.h * Delete forwards.h * Delete json.h * Delete reader.h * Delete value.h * Delete writer.h --- dependencies/CMakeLists.txt | 1 - dependencies/build/jsoncpp/AUTHORS | 1 - dependencies/build/jsoncpp/CMakeLists.txt | 24 - dependencies/build/jsoncpp/LICENSE | 55 - .../build/jsoncpp/json_batchallocator.h | 130 -- .../build/jsoncpp/json_internalarray.inl | 456 ---- .../build/jsoncpp/json_internalmap.inl | 615 ------ dependencies/build/jsoncpp/json_reader.cpp | 880 -------- dependencies/build/jsoncpp/json_tool.h | 93 - dependencies/build/jsoncpp/json_value.cpp | 1829 ----------------- .../build/jsoncpp/json_valueiterator.inl | 299 --- dependencies/build/jsoncpp/json_writer.cpp | 838 -------- dependencies/build/jsoncpp/sconscript | 8 - dependencies/include/json/autolink.h | 24 - dependencies/include/json/config.h | 96 - dependencies/include/json/features.h | 49 - dependencies/include/json/forwards.h | 44 - dependencies/include/json/json.h | 15 - dependencies/include/json/reader.h | 214 -- dependencies/include/json/value.h | 1103 ---------- dependencies/include/json/writer.h | 185 -- include/hyperion/Hyperion.h | 7 +- include/leddevice/LedDevice.h | 6 +- include/leddevice/LedDeviceFactory.h | 5 +- libsrc/hyperion/Hyperion.cpp | 9 +- libsrc/hyperion/LedString.cpp | 3 - libsrc/jsonserver/JsonClientConnection.cpp | 2 +- libsrc/leddevice/LedDevice.cpp | 2 - libsrc/leddevice/LedDeviceAPA102.cpp | 6 +- libsrc/leddevice/LedDeviceAPA102.h | 6 +- libsrc/leddevice/LedDeviceAdalight.cpp | 6 +- libsrc/leddevice/LedDeviceAdalight.h | 6 +- libsrc/leddevice/LedDeviceAdalightApa102.cpp | 6 +- libsrc/leddevice/LedDeviceAdalightApa102.h | 6 +- libsrc/leddevice/LedDeviceAtmo.cpp | 7 +- libsrc/leddevice/LedDeviceAtmo.h | 6 +- libsrc/leddevice/LedDeviceAtmoOrb.cpp | 20 +- libsrc/leddevice/LedDeviceAtmoOrb.h | 8 +- libsrc/leddevice/LedDeviceDMX.cpp | 7 +- libsrc/leddevice/LedDeviceDMX.h | 4 +- libsrc/leddevice/LedDeviceFactory.cpp | 14 +- libsrc/leddevice/LedDeviceFadeCandy.cpp | 34 +- libsrc/leddevice/LedDeviceFadeCandy.h | 7 +- libsrc/leddevice/LedDeviceFile.cpp | 8 +- libsrc/leddevice/LedDeviceFile.h | 6 +- libsrc/leddevice/LedDeviceHyperionUsbasp.cpp | 8 +- libsrc/leddevice/LedDeviceHyperionUsbasp.h | 6 +- libsrc/leddevice/LedDeviceLightpack.cpp | 8 +- libsrc/leddevice/LedDeviceLightpack.h | 6 +- libsrc/leddevice/LedDeviceLpd6803.cpp | 6 +- libsrc/leddevice/LedDeviceLpd6803.h | 6 +- libsrc/leddevice/LedDeviceLpd8806.cpp | 6 +- libsrc/leddevice/LedDeviceLpd8806.h | 6 +- libsrc/leddevice/LedDeviceMultiLightpack.cpp | 4 +- libsrc/leddevice/LedDeviceMultiLightpack.h | 6 +- libsrc/leddevice/LedDeviceP9813.cpp | 6 +- libsrc/leddevice/LedDeviceP9813.h | 6 +- libsrc/leddevice/LedDevicePaintpack.cpp | 4 +- libsrc/leddevice/LedDevicePaintpack.h | 4 +- libsrc/leddevice/LedDevicePhilipsHue.cpp | 71 +- libsrc/leddevice/LedDevicePhilipsHue.h | 6 +- libsrc/leddevice/LedDevicePiBlaster.cpp | 22 +- libsrc/leddevice/LedDevicePiBlaster.h | 6 +- libsrc/leddevice/LedDeviceRawHID.cpp | 4 +- libsrc/leddevice/LedDeviceRawHID.h | 4 +- libsrc/leddevice/LedDeviceSedu.cpp | 6 +- libsrc/leddevice/LedDeviceSedu.h | 6 +- libsrc/leddevice/LedDeviceSk6812SPI.cpp | 8 +- libsrc/leddevice/LedDeviceSk6812SPI.h | 6 +- libsrc/leddevice/LedDeviceTinkerforge.cpp | 14 +- libsrc/leddevice/LedDeviceTinkerforge.h | 6 +- libsrc/leddevice/LedDeviceTpm2.cpp | 6 +- libsrc/leddevice/LedDeviceTpm2.h | 6 +- libsrc/leddevice/LedDeviceTpm2net.cpp | 8 +- libsrc/leddevice/LedDeviceTpm2net.h | 6 +- libsrc/leddevice/LedDeviceUdpE131.cpp | 12 +- libsrc/leddevice/LedDeviceUdpE131.h | 6 +- libsrc/leddevice/LedDeviceUdpH801.cpp | 11 +- libsrc/leddevice/LedDeviceUdpH801.h | 6 +- libsrc/leddevice/LedDeviceUdpRaw.cpp | 4 +- libsrc/leddevice/LedDeviceUdpRaw.h | 4 +- libsrc/leddevice/LedDeviceWS2812b.cpp | 2 +- libsrc/leddevice/LedDeviceWS2812b.h | 4 +- libsrc/leddevice/LedDeviceWS281x.cpp | 23 +- libsrc/leddevice/LedDeviceWS281x.h | 6 +- libsrc/leddevice/LedDeviceWs2801.cpp | 5 +- libsrc/leddevice/LedDeviceWs2801.h | 4 +- libsrc/leddevice/LedDeviceWs2812SPI.cpp | 6 +- libsrc/leddevice/LedDeviceWs2812SPI.h | 6 +- libsrc/leddevice/ProviderHID.cpp | 8 +- libsrc/leddevice/ProviderHID.h | 6 +- libsrc/leddevice/ProviderRs232.cpp | 10 +- libsrc/leddevice/ProviderRs232.h | 2 +- libsrc/leddevice/ProviderSpi.cpp | 12 +- libsrc/leddevice/ProviderSpi.h | 2 +- libsrc/leddevice/ProviderUdp.cpp | 17 +- libsrc/leddevice/ProviderUdp.h | 3 +- libsrc/utils/CMakeLists.txt | 1 - src/hyperiond/hyperiond.cpp | 22 +- src/hyperiond/hyperiond.h | 10 - test/TestSpi.cpp | 9 +- 101 files changed, 313 insertions(+), 7305 deletions(-) delete mode 100644 dependencies/build/jsoncpp/AUTHORS delete mode 100644 dependencies/build/jsoncpp/CMakeLists.txt delete mode 100644 dependencies/build/jsoncpp/LICENSE delete mode 100644 dependencies/build/jsoncpp/json_batchallocator.h delete mode 100644 dependencies/build/jsoncpp/json_internalarray.inl delete mode 100644 dependencies/build/jsoncpp/json_internalmap.inl delete mode 100644 dependencies/build/jsoncpp/json_reader.cpp delete mode 100644 dependencies/build/jsoncpp/json_tool.h delete mode 100644 dependencies/build/jsoncpp/json_value.cpp delete mode 100644 dependencies/build/jsoncpp/json_valueiterator.inl delete mode 100644 dependencies/build/jsoncpp/json_writer.cpp delete mode 100644 dependencies/build/jsoncpp/sconscript delete mode 100644 dependencies/include/json/autolink.h delete mode 100644 dependencies/include/json/config.h delete mode 100644 dependencies/include/json/features.h delete mode 100644 dependencies/include/json/forwards.h delete mode 100644 dependencies/include/json/json.h delete mode 100644 dependencies/include/json/reader.h delete mode 100644 dependencies/include/json/value.h delete mode 100644 dependencies/include/json/writer.h diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index fd1f7ad1..cfaaefc4 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(build/hidapi) -add_subdirectory(build/jsoncpp) add_subdirectory(build/tinkerforge) if(ENABLE_WS281XPWM) diff --git a/dependencies/build/jsoncpp/AUTHORS b/dependencies/build/jsoncpp/AUTHORS deleted file mode 100644 index 333e120d..00000000 --- a/dependencies/build/jsoncpp/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Baptiste Lepilleur diff --git a/dependencies/build/jsoncpp/CMakeLists.txt b/dependencies/build/jsoncpp/CMakeLists.txt deleted file mode 100644 index 8ebd71b7..00000000 --- a/dependencies/build/jsoncpp/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -project(jsoncpp) - -# define the current source/header path -set(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/dependencies/include/json) -set(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/dependencies/build/jsoncpp) - -add_library(jsoncpp - ${CURRENT_HEADER_DIR}/autolink.h - ${CURRENT_HEADER_DIR}/config.h - ${CURRENT_HEADER_DIR}/features.h - ${CURRENT_HEADER_DIR}/forwards.h - ${CURRENT_HEADER_DIR}/json.h - ${CURRENT_HEADER_DIR}/reader.h - ${CURRENT_HEADER_DIR}/value.h - ${CURRENT_HEADER_DIR}/writer.h - - ${CURRENT_SOURCE_DIR}/json_batchallocator.h - ${CURRENT_SOURCE_DIR}/json_internalarray.inl - ${CURRENT_SOURCE_DIR}/json_internalmap.inl - ${CURRENT_SOURCE_DIR}/json_reader.cpp - ${CURRENT_SOURCE_DIR}/json_tool.h - ${CURRENT_SOURCE_DIR}/json_value.cpp - ${CURRENT_SOURCE_DIR}/json_valueiterator.inl - ${CURRENT_SOURCE_DIR}/json_writer.cpp) diff --git a/dependencies/build/jsoncpp/LICENSE b/dependencies/build/jsoncpp/LICENSE deleted file mode 100644 index ca2bfe1a..00000000 --- a/dependencies/build/jsoncpp/LICENSE +++ /dev/null @@ -1,55 +0,0 @@ -The JsonCpp library's source code, including accompanying documentation, -tests and demonstration applications, are licensed under the following -conditions... - -The author (Baptiste Lepilleur) explicitly disclaims copyright in all -jurisdictions which recognize such a disclaimer. In such jurisdictions, -this software is released into the Public Domain. - -In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is -released under the terms of the MIT License (see below). - -In jurisdictions which recognize Public Domain property, the user of this -software may choose to accept it either as 1) Public Domain, 2) under the -conditions of the MIT License (see below), or 3) under the terms of dual -Public Domain/MIT License conditions described here, as they choose. - -The MIT License is about as close to Public Domain as a license can get, and is -described in clear, concise terms at: - - http://en.wikipedia.org/wiki/MIT_License - -The full text of the MIT License follows: - -======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, -modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -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 AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -======================================================================== -(END LICENSE TEXT) - -The MIT license is compatible with both the GPL and commercial -software, affording one all of the rights of Public Domain with the -minor nuisance of being required to keep the above copyright notice -and license text in the source code. Note also that by accepting the -Public Domain "license" you can re-license your copy using whatever -license you like. diff --git a/dependencies/build/jsoncpp/json_batchallocator.h b/dependencies/build/jsoncpp/json_batchallocator.h deleted file mode 100644 index 173e2ed2..00000000 --- a/dependencies/build/jsoncpp/json_batchallocator.h +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED -# define JSONCPP_BATCHALLOCATOR_H_INCLUDED - -# include -# include - -# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - -namespace Json { - -/* Fast memory allocator. - * - * This memory allocator allocates memory for a batch of object (specified by - * the page size, the number of object in each page). - * - * It does not allow the destruction of a single object. All the allocated objects - * can be destroyed at once. The memory can be either released or reused for future - * allocation. - * - * The in-place new operator must be used to construct the object using the pointer - * returned by allocate. - */ -template -class BatchAllocator -{ -public: - typedef AllocatedType Type; - - BatchAllocator( unsigned int objectsPerPage = 255 ) - : freeHead_( 0 ) - , objectsPerPage_( objectsPerPage ) - { -// printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() ); - assert( sizeof(AllocatedType) * objectPerAllocation >= sizeof(AllocatedType *) ); // We must be able to store a slist in the object free space. - assert( objectsPerPage >= 16 ); - batches_ = allocateBatch( 0 ); // allocated a dummy page - currentBatch_ = batches_; - } - - ~BatchAllocator() - { - for ( BatchInfo *batch = batches_; batch; ) - { - BatchInfo *nextBatch = batch->next_; - free( batch ); - batch = nextBatch; - } - } - - /// allocate space for an array of objectPerAllocation object. - /// @warning it is the responsability of the caller to call objects constructors. - AllocatedType *allocate() - { - if ( freeHead_ ) // returns node from free list. - { - AllocatedType *object = freeHead_; - freeHead_ = *(AllocatedType **)object; - return object; - } - if ( currentBatch_->used_ == currentBatch_->end_ ) - { - currentBatch_ = currentBatch_->next_; - while ( currentBatch_ && currentBatch_->used_ == currentBatch_->end_ ) - currentBatch_ = currentBatch_->next_; - - if ( !currentBatch_ ) // no free batch found, allocate a new one - { - currentBatch_ = allocateBatch( objectsPerPage_ ); - currentBatch_->next_ = batches_; // insert at the head of the list - batches_ = currentBatch_; - } - } - AllocatedType *allocated = currentBatch_->used_; - currentBatch_->used_ += objectPerAllocation; - return allocated; - } - - /// Release the object. - /// @warning it is the responsability of the caller to actually destruct the object. - void release( AllocatedType *object ) - { - assert( object != 0 ); - *(AllocatedType **)object = freeHead_; - freeHead_ = object; - } - -private: - struct BatchInfo - { - BatchInfo *next_; - AllocatedType *used_; - AllocatedType *end_; - AllocatedType buffer_[objectPerAllocation]; - }; - - // disabled copy constructor and assignement operator. - BatchAllocator( const BatchAllocator & ); - void operator =( const BatchAllocator &); - - static BatchInfo *allocateBatch( unsigned int objectsPerPage ) - { - const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType)* objectPerAllocation - + sizeof(AllocatedType) * objectPerAllocation * objectsPerPage; - BatchInfo *batch = static_cast( malloc( mallocSize ) ); - batch->next_ = 0; - batch->used_ = batch->buffer_; - batch->end_ = batch->buffer_ + objectsPerPage; - return batch; - } - - BatchInfo *batches_; - BatchInfo *currentBatch_; - /// Head of a single linked list within the allocated space of freeed object - AllocatedType *freeHead_; - unsigned int objectsPerPage_; -}; - - -} // namespace Json - -# endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION - -#endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED - diff --git a/dependencies/build/jsoncpp/json_internalarray.inl b/dependencies/build/jsoncpp/json_internalarray.inl deleted file mode 100644 index 3a532ad7..00000000 --- a/dependencies/build/jsoncpp/json_internalarray.inl +++ /dev/null @@ -1,456 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -// included by json_value.cpp - -namespace Json { - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class ValueInternalArray -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -ValueArrayAllocator::~ValueArrayAllocator() -{ -} - -// ////////////////////////////////////////////////////////////////// -// class DefaultValueArrayAllocator -// ////////////////////////////////////////////////////////////////// -#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -class DefaultValueArrayAllocator : public ValueArrayAllocator -{ -public: // overridden from ValueArrayAllocator - virtual ~DefaultValueArrayAllocator() - { - } - - virtual ValueInternalArray *newArray() - { - return new ValueInternalArray(); - } - - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) - { - return new ValueInternalArray( other ); - } - - virtual void destructArray( ValueInternalArray *array ) - { - delete array; - } - - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) - { - ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; - if ( minNewIndexCount > newIndexCount ) - newIndexCount = minNewIndexCount; - void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); - if ( !newIndexes ) - throw std::bad_alloc(); - indexCount = newIndexCount; - indexes = static_cast( newIndexes ); - } - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) - { - if ( indexes ) - free( indexes ); - } - - virtual Value *allocateArrayPage() - { - return static_cast( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) ); - } - - virtual void releaseArrayPage( Value *value ) - { - if ( value ) - free( value ); - } -}; - -#else // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -/// @todo make this thread-safe (lock when accessign batch allocator) -class DefaultValueArrayAllocator : public ValueArrayAllocator -{ -public: // overridden from ValueArrayAllocator - virtual ~DefaultValueArrayAllocator() - { - } - - virtual ValueInternalArray *newArray() - { - ValueInternalArray *array = arraysAllocator_.allocate(); - new (array) ValueInternalArray(); // placement new - return array; - } - - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) - { - ValueInternalArray *array = arraysAllocator_.allocate(); - new (array) ValueInternalArray( other ); // placement new - return array; - } - - virtual void destructArray( ValueInternalArray *array ) - { - if ( array ) - { - array->~ValueInternalArray(); - arraysAllocator_.release( array ); - } - } - - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) - { - ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; - if ( minNewIndexCount > newIndexCount ) - newIndexCount = minNewIndexCount; - void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); - if ( !newIndexes ) - throw std::bad_alloc(); - indexCount = newIndexCount; - indexes = static_cast( newIndexes ); - } - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) - { - if ( indexes ) - free( indexes ); - } - - virtual Value *allocateArrayPage() - { - return static_cast( pagesAllocator_.allocate() ); - } - - virtual void releaseArrayPage( Value *value ) - { - if ( value ) - pagesAllocator_.release( value ); - } -private: - BatchAllocator arraysAllocator_; - BatchAllocator pagesAllocator_; -}; -#endif // #ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR - -static ValueArrayAllocator *&arrayAllocator() -{ - static DefaultValueArrayAllocator defaultAllocator; - static ValueArrayAllocator *arrayAllocator = &defaultAllocator; - return arrayAllocator; -} - -static struct DummyArrayAllocatorInitializer { - DummyArrayAllocatorInitializer() - { - arrayAllocator(); // ensure arrayAllocator() statics are initialized before main(). - } -} dummyArrayAllocatorInitializer; - -// ////////////////////////////////////////////////////////////////// -// class ValueInternalArray -// ////////////////////////////////////////////////////////////////// -bool -ValueInternalArray::equals( const IteratorState &x, - const IteratorState &other ) -{ - return x.array_ == other.array_ - && x.currentItemIndex_ == other.currentItemIndex_ - && x.currentPageIndex_ == other.currentPageIndex_; -} - - -void -ValueInternalArray::increment( IteratorState &it ) -{ - JSON_ASSERT_MESSAGE( it.array_ && - (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_ - != it.array_->size_, - "ValueInternalArray::increment(): moving iterator beyond end" ); - ++(it.currentItemIndex_); - if ( it.currentItemIndex_ == itemsPerPage ) - { - it.currentItemIndex_ = 0; - ++(it.currentPageIndex_); - } -} - - -void -ValueInternalArray::decrement( IteratorState &it ) -{ - JSON_ASSERT_MESSAGE( it.array_ && it.currentPageIndex_ == it.array_->pages_ - && it.currentItemIndex_ == 0, - "ValueInternalArray::decrement(): moving iterator beyond end" ); - if ( it.currentItemIndex_ == 0 ) - { - it.currentItemIndex_ = itemsPerPage-1; - --(it.currentPageIndex_); - } - else - { - --(it.currentItemIndex_); - } -} - - -Value & -ValueInternalArray::unsafeDereference( const IteratorState &it ) -{ - return (*(it.currentPageIndex_))[it.currentItemIndex_]; -} - - -Value & -ValueInternalArray::dereference( const IteratorState &it ) -{ - JSON_ASSERT_MESSAGE( it.array_ && - (it.currentPageIndex_ - it.array_->pages_)*itemsPerPage + it.currentItemIndex_ - < it.array_->size_, - "ValueInternalArray::dereference(): dereferencing invalid iterator" ); - return unsafeDereference( it ); -} - -void -ValueInternalArray::makeBeginIterator( IteratorState &it ) const -{ - it.array_ = const_cast( this ); - it.currentItemIndex_ = 0; - it.currentPageIndex_ = pages_; -} - - -void -ValueInternalArray::makeIterator( IteratorState &it, ArrayIndex index ) const -{ - it.array_ = const_cast( this ); - it.currentItemIndex_ = index % itemsPerPage; - it.currentPageIndex_ = pages_ + index / itemsPerPage; -} - - -void -ValueInternalArray::makeEndIterator( IteratorState &it ) const -{ - makeIterator( it, size_ ); -} - - -ValueInternalArray::ValueInternalArray() - : pages_( 0 ) - , size_( 0 ) - , pageCount_( 0 ) -{ -} - - -ValueInternalArray::ValueInternalArray( const ValueInternalArray &other ) - : pages_( 0 ) - , pageCount_( 0 ) - , size_( other.size_ ) -{ - PageIndex minNewPages = other.size_ / itemsPerPage; - arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages ); - JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, - "ValueInternalArray::reserve(): bad reallocation" ); - IteratorState itOther; - other.makeBeginIterator( itOther ); - Value *value; - for ( ArrayIndex index = 0; index < size_; ++index, increment(itOther) ) - { - if ( index % itemsPerPage == 0 ) - { - PageIndex pageIndex = index / itemsPerPage; - value = arrayAllocator()->allocateArrayPage(); - pages_[pageIndex] = value; - } - new (value) Value( dereference( itOther ) ); - } -} - - -ValueInternalArray & -ValueInternalArray::operator =( const ValueInternalArray &other ) -{ - ValueInternalArray temp( other ); - swap( temp ); - return *this; -} - - -ValueInternalArray::~ValueInternalArray() -{ - // destroy all constructed items - IteratorState it; - IteratorState itEnd; - makeBeginIterator( it); - makeEndIterator( itEnd ); - for ( ; !equals(it,itEnd); increment(it) ) - { - Value *value = &dereference(it); - value->~Value(); - } - // release all pages - PageIndex lastPageIndex = size_ / itemsPerPage; - for ( PageIndex pageIndex = 0; pageIndex < lastPageIndex; ++pageIndex ) - arrayAllocator()->releaseArrayPage( pages_[pageIndex] ); - // release pages index - arrayAllocator()->releaseArrayPageIndex( pages_, pageCount_ ); -} - - -void -ValueInternalArray::swap( ValueInternalArray &other ) -{ - Value **tempPages = pages_; - pages_ = other.pages_; - other.pages_ = tempPages; - ArrayIndex tempSize = size_; - size_ = other.size_; - other.size_ = tempSize; - PageIndex tempPageCount = pageCount_; - pageCount_ = other.pageCount_; - other.pageCount_ = tempPageCount; -} - -void -ValueInternalArray::clear() -{ - ValueInternalArray dummy; - swap( dummy ); -} - - -void -ValueInternalArray::resize( ArrayIndex newSize ) -{ - if ( newSize == 0 ) - clear(); - else if ( newSize < size_ ) - { - IteratorState it; - IteratorState itEnd; - makeIterator( it, newSize ); - makeIterator( itEnd, size_ ); - for ( ; !equals(it,itEnd); increment(it) ) - { - Value *value = &dereference(it); - value->~Value(); - } - PageIndex pageIndex = (newSize + itemsPerPage - 1) / itemsPerPage; - PageIndex lastPageIndex = size_ / itemsPerPage; - for ( ; pageIndex < lastPageIndex; ++pageIndex ) - arrayAllocator()->releaseArrayPage( pages_[pageIndex] ); - size_ = newSize; - } - else if ( newSize > size_ ) - resolveReference( newSize ); -} - - -void -ValueInternalArray::makeIndexValid( ArrayIndex index ) -{ - // Need to enlarge page index ? - if ( index >= pageCount_ * itemsPerPage ) - { - PageIndex minNewPages = (index + 1) / itemsPerPage; - arrayAllocator()->reallocateArrayPageIndex( pages_, pageCount_, minNewPages ); - JSON_ASSERT_MESSAGE( pageCount_ >= minNewPages, "ValueInternalArray::reserve(): bad reallocation" ); - } - - // Need to allocate new pages ? - ArrayIndex nextPageIndex = - (size_ % itemsPerPage) != 0 ? size_ - (size_%itemsPerPage) + itemsPerPage - : size_; - if ( nextPageIndex <= index ) - { - PageIndex pageIndex = nextPageIndex / itemsPerPage; - PageIndex pageToAllocate = (index - nextPageIndex) / itemsPerPage + 1; - for ( ; pageToAllocate-- > 0; ++pageIndex ) - pages_[pageIndex] = arrayAllocator()->allocateArrayPage(); - } - - // Initialize all new entries - IteratorState it; - IteratorState itEnd; - makeIterator( it, size_ ); - size_ = index + 1; - makeIterator( itEnd, size_ ); - for ( ; !equals(it,itEnd); increment(it) ) - { - Value *value = &dereference(it); - new (value) Value(); // Construct a default value using placement new - } -} - -Value & -ValueInternalArray::resolveReference( ArrayIndex index ) -{ - if ( index >= size_ ) - makeIndexValid( index ); - return pages_[index/itemsPerPage][index%itemsPerPage]; -} - -Value * -ValueInternalArray::find( ArrayIndex index ) const -{ - if ( index >= size_ ) - return 0; - return &(pages_[index/itemsPerPage][index%itemsPerPage]); -} - -ValueInternalArray::ArrayIndex -ValueInternalArray::size() const -{ - return size_; -} - -int -ValueInternalArray::distance( const IteratorState &x, const IteratorState &y ) -{ - return indexOf(y) - indexOf(x); -} - - -ValueInternalArray::ArrayIndex -ValueInternalArray::indexOf( const IteratorState &iterator ) -{ - if ( !iterator.array_ ) - return ArrayIndex(-1); - return ArrayIndex( - (iterator.currentPageIndex_ - iterator.array_->pages_) * itemsPerPage - + iterator.currentItemIndex_ ); -} - - -int -ValueInternalArray::compare( const ValueInternalArray &other ) const -{ - int sizeDiff( size_ - other.size_ ); - if ( sizeDiff != 0 ) - return sizeDiff; - - for ( ArrayIndex index =0; index < size_; ++index ) - { - int diff = pages_[index/itemsPerPage][index%itemsPerPage].compare( - other.pages_[index/itemsPerPage][index%itemsPerPage] ); - if ( diff != 0 ) - return diff; - } - return 0; -} - -} // namespace Json diff --git a/dependencies/build/jsoncpp/json_internalmap.inl b/dependencies/build/jsoncpp/json_internalmap.inl deleted file mode 100644 index f2fa1606..00000000 --- a/dependencies/build/jsoncpp/json_internalmap.inl +++ /dev/null @@ -1,615 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -// included by json_value.cpp - -namespace Json { - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class ValueInternalMap -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -/** \internal MUST be safely initialized using memset( this, 0, sizeof(ValueInternalLink) ); - * This optimization is used by the fast allocator. - */ -ValueInternalLink::ValueInternalLink() - : previous_( 0 ) - , next_( 0 ) -{ -} - -ValueInternalLink::~ValueInternalLink() -{ - for ( int index =0; index < itemPerLink; ++index ) - { - if ( !items_[index].isItemAvailable() ) - { - if ( !items_[index].isMemberNameStatic() ) - free( keys_[index] ); - } - else - break; - } -} - - - -ValueMapAllocator::~ValueMapAllocator() -{ -} - -#ifdef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -class DefaultValueMapAllocator : public ValueMapAllocator -{ -public: // overridden from ValueMapAllocator - virtual ValueInternalMap *newMap() - { - return new ValueInternalMap(); - } - - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) - { - return new ValueInternalMap( other ); - } - - virtual void destructMap( ValueInternalMap *map ) - { - delete map; - } - - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) - { - return new ValueInternalLink[size]; - } - - virtual void releaseMapBuckets( ValueInternalLink *links ) - { - delete [] links; - } - - virtual ValueInternalLink *allocateMapLink() - { - return new ValueInternalLink(); - } - - virtual void releaseMapLink( ValueInternalLink *link ) - { - delete link; - } -}; -#else -/// @todo make this thread-safe (lock when accessign batch allocator) -class DefaultValueMapAllocator : public ValueMapAllocator -{ -public: // overridden from ValueMapAllocator - virtual ValueInternalMap *newMap() - { - ValueInternalMap *map = mapsAllocator_.allocate(); - new (map) ValueInternalMap(); // placement new - return map; - } - - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) - { - ValueInternalMap *map = mapsAllocator_.allocate(); - new (map) ValueInternalMap( other ); // placement new - return map; - } - - virtual void destructMap( ValueInternalMap *map ) - { - if ( map ) - { - map->~ValueInternalMap(); - mapsAllocator_.release( map ); - } - } - - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) - { - return new ValueInternalLink[size]; - } - - virtual void releaseMapBuckets( ValueInternalLink *links ) - { - delete [] links; - } - - virtual ValueInternalLink *allocateMapLink() - { - ValueInternalLink *link = linksAllocator_.allocate(); - memset( link, 0, sizeof(ValueInternalLink) ); - return link; - } - - virtual void releaseMapLink( ValueInternalLink *link ) - { - link->~ValueInternalLink(); - linksAllocator_.release( link ); - } -private: - BatchAllocator mapsAllocator_; - BatchAllocator linksAllocator_; -}; -#endif - -static ValueMapAllocator *&mapAllocator() -{ - static DefaultValueMapAllocator defaultAllocator; - static ValueMapAllocator *mapAllocator = &defaultAllocator; - return mapAllocator; -} - -static struct DummyMapAllocatorInitializer { - DummyMapAllocatorInitializer() - { - mapAllocator(); // ensure mapAllocator() statics are initialized before main(). - } -} dummyMapAllocatorInitializer; - - - -// h(K) = value * K >> w ; with w = 32 & K prime w.r.t. 2^32. - -/* -use linked list hash map. -buckets array is a container. -linked list element contains 6 key/values. (memory = (16+4) * 6 + 4 = 124) -value have extra state: valid, available, deleted -*/ - - -ValueInternalMap::ValueInternalMap() - : buckets_( 0 ) - , tailLink_( 0 ) - , bucketsSize_( 0 ) - , itemCount_( 0 ) -{ -} - - -ValueInternalMap::ValueInternalMap( const ValueInternalMap &other ) - : buckets_( 0 ) - , tailLink_( 0 ) - , bucketsSize_( 0 ) - , itemCount_( 0 ) -{ - reserve( other.itemCount_ ); - IteratorState it; - IteratorState itEnd; - other.makeBeginIterator( it ); - other.makeEndIterator( itEnd ); - for ( ; !equals(it,itEnd); increment(it) ) - { - bool isStatic; - const char *memberName = key( it, isStatic ); - const Value &aValue = value( it ); - resolveReference(memberName, isStatic) = aValue; - } -} - - -ValueInternalMap & -ValueInternalMap::operator =( const ValueInternalMap &other ) -{ - ValueInternalMap dummy( other ); - swap( dummy ); - return *this; -} - - -ValueInternalMap::~ValueInternalMap() -{ - if ( buckets_ ) - { - for ( BucketIndex bucketIndex =0; bucketIndex < bucketsSize_; ++bucketIndex ) - { - ValueInternalLink *link = buckets_[bucketIndex].next_; - while ( link ) - { - ValueInternalLink *linkToRelease = link; - link = link->next_; - mapAllocator()->releaseMapLink( linkToRelease ); - } - } - mapAllocator()->releaseMapBuckets( buckets_ ); - } -} - - -void -ValueInternalMap::swap( ValueInternalMap &other ) -{ - ValueInternalLink *tempBuckets = buckets_; - buckets_ = other.buckets_; - other.buckets_ = tempBuckets; - ValueInternalLink *tempTailLink = tailLink_; - tailLink_ = other.tailLink_; - other.tailLink_ = tempTailLink; - BucketIndex tempBucketsSize = bucketsSize_; - bucketsSize_ = other.bucketsSize_; - other.bucketsSize_ = tempBucketsSize; - BucketIndex tempItemCount = itemCount_; - itemCount_ = other.itemCount_; - other.itemCount_ = tempItemCount; -} - - -void -ValueInternalMap::clear() -{ - ValueInternalMap dummy; - swap( dummy ); -} - - -ValueInternalMap::BucketIndex -ValueInternalMap::size() const -{ - return itemCount_; -} - -bool -ValueInternalMap::reserveDelta( BucketIndex growth ) -{ - return reserve( itemCount_ + growth ); -} - -bool -ValueInternalMap::reserve( BucketIndex newItemCount ) -{ - if ( !buckets_ && newItemCount > 0 ) - { - buckets_ = mapAllocator()->allocateMapBuckets( 1 ); - bucketsSize_ = 1; - tailLink_ = &buckets_[0]; - } -// BucketIndex idealBucketCount = (newItemCount + ValueInternalLink::itemPerLink) / ValueInternalLink::itemPerLink; - return true; -} - - -const Value * -ValueInternalMap::find( const char *key ) const -{ - if ( !bucketsSize_ ) - return 0; - HashKey hashedKey = hash( key ); - BucketIndex bucketIndex = hashedKey % bucketsSize_; - for ( const ValueInternalLink *current = &buckets_[bucketIndex]; - current != 0; - current = current->next_ ) - { - for ( BucketIndex index=0; index < ValueInternalLink::itemPerLink; ++index ) - { - if ( current->items_[index].isItemAvailable() ) - return 0; - if ( strcmp( key, current->keys_[index] ) == 0 ) - return ¤t->items_[index]; - } - } - return 0; -} - - -Value * -ValueInternalMap::find( const char *key ) -{ - const ValueInternalMap *constThis = this; - return const_cast( constThis->find( key ) ); -} - - -Value & -ValueInternalMap::resolveReference( const char *key, - bool isStatic ) -{ - HashKey hashedKey = hash( key ); - if ( bucketsSize_ ) - { - BucketIndex bucketIndex = hashedKey % bucketsSize_; - ValueInternalLink **previous = 0; - BucketIndex index; - for ( ValueInternalLink *current = &buckets_[bucketIndex]; - current != 0; - previous = ¤t->next_, current = current->next_ ) - { - for ( index=0; index < ValueInternalLink::itemPerLink; ++index ) - { - if ( current->items_[index].isItemAvailable() ) - return setNewItem( key, isStatic, current, index ); - if ( strcmp( key, current->keys_[index] ) == 0 ) - return current->items_[index]; - } - } - } - - reserveDelta( 1 ); - return unsafeAdd( key, isStatic, hashedKey ); -} - - -void -ValueInternalMap::remove( const char *key ) -{ - HashKey hashedKey = hash( key ); - if ( !bucketsSize_ ) - return; - BucketIndex bucketIndex = hashedKey % bucketsSize_; - for ( ValueInternalLink *link = &buckets_[bucketIndex]; - link != 0; - link = link->next_ ) - { - BucketIndex index; - for ( index =0; index < ValueInternalLink::itemPerLink; ++index ) - { - if ( link->items_[index].isItemAvailable() ) - return; - if ( strcmp( key, link->keys_[index] ) == 0 ) - { - doActualRemove( link, index, bucketIndex ); - return; - } - } - } -} - -void -ValueInternalMap::doActualRemove( ValueInternalLink *link, - BucketIndex index, - BucketIndex bucketIndex ) -{ - // find last item of the bucket and swap it with the 'removed' one. - // set removed items flags to 'available'. - // if last page only contains 'available' items, then desallocate it (it's empty) - ValueInternalLink *&lastLink = getLastLinkInBucket( index ); - BucketIndex lastItemIndex = 1; // a link can never be empty, so start at 1 - for ( ; - lastItemIndex < ValueInternalLink::itemPerLink; - ++lastItemIndex ) // may be optimized with dicotomic search - { - if ( lastLink->items_[lastItemIndex].isItemAvailable() ) - break; - } - - BucketIndex lastUsedIndex = lastItemIndex - 1; - Value *valueToDelete = &link->items_[index]; - Value *valueToPreserve = &lastLink->items_[lastUsedIndex]; - if ( valueToDelete != valueToPreserve ) - valueToDelete->swap( *valueToPreserve ); - if ( lastUsedIndex == 0 ) // page is now empty - { // remove it from bucket linked list and delete it. - ValueInternalLink *linkPreviousToLast = lastLink->previous_; - if ( linkPreviousToLast != 0 ) // can not deleted bucket link. - { - mapAllocator()->releaseMapLink( lastLink ); - linkPreviousToLast->next_ = 0; - lastLink = linkPreviousToLast; - } - } - else - { - Value dummy; - valueToPreserve->swap( dummy ); // restore deleted to default Value. - valueToPreserve->setItemUsed( false ); - } - --itemCount_; -} - - -ValueInternalLink *& -ValueInternalMap::getLastLinkInBucket( BucketIndex bucketIndex ) -{ - if ( bucketIndex == bucketsSize_ - 1 ) - return tailLink_; - ValueInternalLink *&previous = buckets_[bucketIndex+1].previous_; - if ( !previous ) - previous = &buckets_[bucketIndex]; - return previous; -} - - -Value & -ValueInternalMap::setNewItem( const char *key, - bool isStatic, - ValueInternalLink *link, - BucketIndex index ) -{ - char *duplicatedKey = makeMemberName( key ); - ++itemCount_; - link->keys_[index] = duplicatedKey; - link->items_[index].setItemUsed(); - link->items_[index].setMemberNameIsStatic( isStatic ); - return link->items_[index]; // items already default constructed. -} - - -Value & -ValueInternalMap::unsafeAdd( const char *key, - bool isStatic, - HashKey hashedKey ) -{ - JSON_ASSERT_MESSAGE( bucketsSize_ > 0, "ValueInternalMap::unsafeAdd(): internal logic error." ); - BucketIndex bucketIndex = hashedKey % bucketsSize_; - ValueInternalLink *&previousLink = getLastLinkInBucket( bucketIndex ); - ValueInternalLink *link = previousLink; - BucketIndex index; - for ( index =0; index < ValueInternalLink::itemPerLink; ++index ) - { - if ( link->items_[index].isItemAvailable() ) - break; - } - if ( index == ValueInternalLink::itemPerLink ) // need to add a new page - { - ValueInternalLink *newLink = mapAllocator()->allocateMapLink(); - index = 0; - link->next_ = newLink; - previousLink = newLink; - link = newLink; - } - return setNewItem( key, isStatic, link, index ); -} - - -ValueInternalMap::HashKey -ValueInternalMap::hash( const char *key ) const -{ - HashKey hash = 0; - while ( *key ) - hash += *key++ * 37; - return hash; -} - - -int -ValueInternalMap::compare( const ValueInternalMap &other ) const -{ - int sizeDiff( itemCount_ - other.itemCount_ ); - if ( sizeDiff != 0 ) - return sizeDiff; - // Strict order guaranty is required. Compare all keys FIRST, then compare values. - IteratorState it; - IteratorState itEnd; - makeBeginIterator( it ); - makeEndIterator( itEnd ); - for ( ; !equals(it,itEnd); increment(it) ) - { - if ( !other.find( key( it ) ) ) - return 1; - } - - // All keys are equals, let's compare values - makeBeginIterator( it ); - for ( ; !equals(it,itEnd); increment(it) ) - { - const Value *otherValue = other.find( key( it ) ); - int valueDiff = value(it).compare( *otherValue ); - if ( valueDiff != 0 ) - return valueDiff; - } - return 0; -} - - -void -ValueInternalMap::makeBeginIterator( IteratorState &it ) const -{ - it.map_ = const_cast( this ); - it.bucketIndex_ = 0; - it.itemIndex_ = 0; - it.link_ = buckets_; -} - - -void -ValueInternalMap::makeEndIterator( IteratorState &it ) const -{ - it.map_ = const_cast( this ); - it.bucketIndex_ = bucketsSize_; - it.itemIndex_ = 0; - it.link_ = 0; -} - - -bool -ValueInternalMap::equals( const IteratorState &x, const IteratorState &other ) -{ - return x.map_ == other.map_ - && x.bucketIndex_ == other.bucketIndex_ - && x.link_ == other.link_ - && x.itemIndex_ == other.itemIndex_; -} - - -void -ValueInternalMap::incrementBucket( IteratorState &iterator ) -{ - ++iterator.bucketIndex_; - JSON_ASSERT_MESSAGE( iterator.bucketIndex_ <= iterator.map_->bucketsSize_, - "ValueInternalMap::increment(): attempting to iterate beyond end." ); - if ( iterator.bucketIndex_ == iterator.map_->bucketsSize_ ) - iterator.link_ = 0; - else - iterator.link_ = &(iterator.map_->buckets_[iterator.bucketIndex_]); - iterator.itemIndex_ = 0; -} - - -void -ValueInternalMap::increment( IteratorState &iterator ) -{ - JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterator using invalid iterator." ); - ++iterator.itemIndex_; - if ( iterator.itemIndex_ == ValueInternalLink::itemPerLink ) - { - JSON_ASSERT_MESSAGE( iterator.link_ != 0, - "ValueInternalMap::increment(): attempting to iterate beyond end." ); - iterator.link_ = iterator.link_->next_; - if ( iterator.link_ == 0 ) - incrementBucket( iterator ); - } - else if ( iterator.link_->items_[iterator.itemIndex_].isItemAvailable() ) - { - incrementBucket( iterator ); - } -} - - -void -ValueInternalMap::decrement( IteratorState &iterator ) -{ - if ( iterator.itemIndex_ == 0 ) - { - JSON_ASSERT_MESSAGE( iterator.map_, "Attempting to iterate using invalid iterator." ); - if ( iterator.link_ == &iterator.map_->buckets_[iterator.bucketIndex_] ) - { - JSON_ASSERT_MESSAGE( iterator.bucketIndex_ > 0, "Attempting to iterate beyond beginning." ); - --(iterator.bucketIndex_); - } - iterator.link_ = iterator.link_->previous_; - iterator.itemIndex_ = ValueInternalLink::itemPerLink - 1; - } -} - - -const char * -ValueInternalMap::key( const IteratorState &iterator ) -{ - JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); - return iterator.link_->keys_[iterator.itemIndex_]; -} - -const char * -ValueInternalMap::key( const IteratorState &iterator, bool &isStatic ) -{ - JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); - isStatic = iterator.link_->items_[iterator.itemIndex_].isMemberNameStatic(); - return iterator.link_->keys_[iterator.itemIndex_]; -} - - -Value & -ValueInternalMap::value( const IteratorState &iterator ) -{ - JSON_ASSERT_MESSAGE( iterator.link_, "Attempting to iterate using invalid iterator." ); - return iterator.link_->items_[iterator.itemIndex_]; -} - - -int -ValueInternalMap::distance( const IteratorState &x, const IteratorState &y ) -{ - int offset = 0; - IteratorState it = x; - while ( !equals( it, y ) ) - increment( it ); - return offset; -} - -} // namespace Json diff --git a/dependencies/build/jsoncpp/json_reader.cpp b/dependencies/build/jsoncpp/json_reader.cpp deleted file mode 100644 index 8bb03042..00000000 --- a/dependencies/build/jsoncpp/json_reader.cpp +++ /dev/null @@ -1,880 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#if !defined(JSON_IS_AMALGAMATION) -# include -# include -# include "json_tool.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -#include -#include -#include -#include -#include -#include - -#if _MSC_VER >= 1400 // VC++ 8.0 -#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. -#endif - -namespace Json { - -// Implementation of class Features -// //////////////////////////////// - -Features::Features() - : allowComments_( true ) - , strictRoot_( false ) -{ -} - - -Features -Features::all() -{ - return Features(); -} - - -Features -Features::strictMode() -{ - Features features; - features.allowComments_ = false; - features.strictRoot_ = true; - return features; -} - -// Implementation of class Reader -// //////////////////////////////// - - -static inline bool -in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 ) -{ - return c == c1 || c == c2 || c == c3 || c == c4; -} - -static inline bool -in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 ) -{ - return c == c1 || c == c2 || c == c3 || c == c4 || c == c5; -} - - -static bool -containsNewLine( Reader::Location begin, - Reader::Location end ) -{ - for ( ;begin < end; ++begin ) - if ( *begin == '\n' || *begin == '\r' ) - return true; - return false; -} - - -// Class Reader -// ////////////////////////////////////////////////////////////////// - -Reader::Reader() - : features_( Features::all() ) -{ -} - - -Reader::Reader( const Features &features ) - : features_( features ) -{ -} - - -bool -Reader::parse( const std::string &document, - Value &root, - bool collectComments ) -{ - document_ = document; - const char *begin = document_.c_str(); - const char *end = begin + document_.length(); - return parse( begin, end, root, collectComments ); -} - - -bool -Reader::parse( std::istream& sin, - Value &root, - bool collectComments ) -{ - //std::istream_iterator begin(sin); - //std::istream_iterator end; - // Those would allow streamed input from a file, if parse() were a - // template function. - - // Since std::string is reference-counted, this at least does not - // create an extra copy. - std::string doc; - std::getline(sin, doc, (char)EOF); - return parse( doc, root, collectComments ); -} - -bool -Reader::parse( const char *beginDoc, const char *endDoc, - Value &root, - bool collectComments ) -{ - if ( !features_.allowComments_ ) - { - collectComments = false; - } - - begin_ = beginDoc; - end_ = endDoc; - collectComments_ = collectComments; - current_ = begin_; - lastValueEnd_ = 0; - lastValue_ = 0; - commentsBefore_ = ""; - errors_.clear(); - while ( !nodes_.empty() ) - nodes_.pop(); - nodes_.push( &root ); - - bool successful = readValue(); - Token token; - skipCommentTokens( token ); - if ( collectComments_ && !commentsBefore_.empty() ) - root.setComment( commentsBefore_, commentAfter ); - if ( features_.strictRoot_ ) - { - if ( !root.isArray() && !root.isObject() ) - { - // Set error location to start of doc, ideally should be first token found in doc - token.type_ = tokenError; - token.start_ = beginDoc; - token.end_ = endDoc; - addError( "A valid JSON document must be either an array or an object value.", - token ); - return false; - } - } - return successful; -} - - -bool -Reader::readValue() -{ - Token token; - skipCommentTokens( token ); - bool successful = true; - - if ( collectComments_ && !commentsBefore_.empty() ) - { - currentValue().setComment( commentsBefore_, commentBefore ); - commentsBefore_ = ""; - } - - - switch ( token.type_ ) - { - case tokenObjectBegin: - successful = readObject( token ); - break; - case tokenArrayBegin: - successful = readArray( token ); - break; - case tokenNumber: - successful = decodeNumber( token ); - break; - case tokenString: - successful = decodeString( token ); - break; - case tokenTrue: - currentValue() = true; - break; - case tokenFalse: - currentValue() = false; - break; - case tokenNull: - currentValue() = Value(); - break; - default: - return addError( "Syntax error: value, object or array expected.", token ); - } - - if ( collectComments_ ) - { - lastValueEnd_ = current_; - lastValue_ = ¤tValue(); - } - - return successful; -} - - -void -Reader::skipCommentTokens( Token &token ) -{ - if ( features_.allowComments_ ) - { - do - { - readToken( token ); - } - while ( token.type_ == tokenComment ); - } - else - { - readToken( token ); - } -} - - -bool -Reader::expectToken( TokenType type, Token &token, const char *message ) -{ - readToken( token ); - if ( token.type_ != type ) - return addError( message, token ); - return true; -} - - -bool -Reader::readToken( Token &token ) -{ - skipSpaces(); - token.start_ = current_; - Char c = getNextChar(); - bool ok = true; - switch ( c ) - { - case '{': - token.type_ = tokenObjectBegin; - break; - case '}': - token.type_ = tokenObjectEnd; - break; - case '[': - token.type_ = tokenArrayBegin; - break; - case ']': - token.type_ = tokenArrayEnd; - break; - case '"': - token.type_ = tokenString; - ok = readString(); - break; - case '/': - token.type_ = tokenComment; - ok = readComment(); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '-': - token.type_ = tokenNumber; - readNumber(); - break; - case 't': - token.type_ = tokenTrue; - ok = match( "rue", 3 ); - break; - case 'f': - token.type_ = tokenFalse; - ok = match( "alse", 4 ); - break; - case 'n': - token.type_ = tokenNull; - ok = match( "ull", 3 ); - break; - case ',': - token.type_ = tokenArraySeparator; - break; - case ':': - token.type_ = tokenMemberSeparator; - break; - case 0: - token.type_ = tokenEndOfStream; - break; - default: - ok = false; - break; - } - if ( !ok ) - token.type_ = tokenError; - token.end_ = current_; - return true; -} - - -void -Reader::skipSpaces() -{ - while ( current_ != end_ ) - { - Char c = *current_; - if ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) - ++current_; - else - break; - } -} - - -bool -Reader::match( Location pattern, - int patternLength ) -{ - if ( end_ - current_ < patternLength ) - return false; - int index = patternLength; - while ( index-- ) - if ( current_[index] != pattern[index] ) - return false; - current_ += patternLength; - return true; -} - - -bool -Reader::readComment() -{ - Location commentBegin = current_ - 1; - Char c = getNextChar(); - bool successful = false; - if ( c == '*' ) - successful = readCStyleComment(); - else if ( c == '/' ) - successful = readCppStyleComment(); - if ( !successful ) - return false; - - if ( collectComments_ ) - { - CommentPlacement placement = commentBefore; - if ( lastValueEnd_ && !containsNewLine( lastValueEnd_, commentBegin ) ) - { - if ( c != '*' || !containsNewLine( commentBegin, current_ ) ) - placement = commentAfterOnSameLine; - } - - addComment( commentBegin, current_, placement ); - } - return true; -} - - -void -Reader::addComment( Location begin, - Location end, - CommentPlacement placement ) -{ - assert( collectComments_ ); - if ( placement == commentAfterOnSameLine ) - { - assert( lastValue_ != 0 ); - lastValue_->setComment( std::string( begin, end ), placement ); - } - else - { - if ( !commentsBefore_.empty() ) - commentsBefore_ += "\n"; - commentsBefore_ += std::string( begin, end ); - } -} - - -bool -Reader::readCStyleComment() -{ - while ( current_ != end_ ) - { - Char c = getNextChar(); - if ( c == '*' && *current_ == '/' ) - break; - } - return getNextChar() == '/'; -} - - -bool -Reader::readCppStyleComment() -{ - while ( current_ != end_ ) - { - Char c = getNextChar(); - if ( c == '\r' || c == '\n' ) - break; - } - return true; -} - - -void -Reader::readNumber() -{ - while ( current_ != end_ ) - { - if ( !(*current_ >= '0' && *current_ <= '9') && - !in( *current_, '.', 'e', 'E', '+', '-' ) ) - break; - ++current_; - } -} - -bool -Reader::readString() -{ - Char c = 0; - while ( current_ != end_ ) - { - c = getNextChar(); - if ( c == '\\' ) - getNextChar(); - else if ( c == '"' ) - break; - } - return c == '"'; -} - - -bool -Reader::readObject( Token &/*tokenStart*/ ) -{ - Token tokenName; - std::string name; - currentValue() = Value( objectValue ); - while ( readToken( tokenName ) ) - { - bool initialTokenOk = true; - while ( tokenName.type_ == tokenComment && initialTokenOk ) - initialTokenOk = readToken( tokenName ); - if ( !initialTokenOk ) - break; - if ( tokenName.type_ == tokenObjectEnd && name.empty() ) // empty object - return true; - if ( tokenName.type_ != tokenString ) - break; - - name = ""; - if ( !decodeString( tokenName, name ) ) - return recoverFromError( tokenObjectEnd ); - - Token colon; - if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) - { - return addErrorAndRecover( "Missing ':' after object member name", - colon, - tokenObjectEnd ); - } - Value &value = currentValue()[ name ]; - nodes_.push( &value ); - bool ok = readValue(); - nodes_.pop(); - if ( !ok ) // error already set - return recoverFromError( tokenObjectEnd ); - - Token comma; - if ( !readToken( comma ) - || ( comma.type_ != tokenObjectEnd && - comma.type_ != tokenArraySeparator && - comma.type_ != tokenComment ) ) - { - return addErrorAndRecover( "Missing ',' or '}' in object declaration", - comma, - tokenObjectEnd ); - } - bool finalizeTokenOk = true; - while ( comma.type_ == tokenComment && - finalizeTokenOk ) - finalizeTokenOk = readToken( comma ); - if ( comma.type_ == tokenObjectEnd ) - return true; - } - return addErrorAndRecover( "Missing '}' or object member name", - tokenName, - tokenObjectEnd ); -} - - -bool -Reader::readArray( Token &/*tokenStart*/ ) -{ - currentValue() = Value( arrayValue ); - skipSpaces(); - if ( *current_ == ']' ) // empty array - { - Token endArray; - readToken( endArray ); - return true; - } - int index = 0; - for (;;) - { - Value &value = currentValue()[ index++ ]; - nodes_.push( &value ); - bool ok = readValue(); - nodes_.pop(); - if ( !ok ) // error already set - return recoverFromError( tokenArrayEnd ); - - Token token; - // Accept Comment after last item in the array. - ok = readToken( token ); - while ( token.type_ == tokenComment && ok ) - { - ok = readToken( token ); - } - bool badTokenType = ( token.type_ != tokenArraySeparator && - token.type_ != tokenArrayEnd ); - if ( !ok || badTokenType ) - { - return addErrorAndRecover( "Missing ',' or ']' in array declaration", - token, - tokenArrayEnd ); - } - if ( token.type_ == tokenArrayEnd ) - break; - } - return true; -} - - -bool -Reader::decodeNumber( Token &token ) -{ - bool isDouble = false; - for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) - { - isDouble = isDouble - || in( *inspect, '.', 'e', 'E', '+' ) - || ( *inspect == '-' && inspect != token.start_ ); - } - if ( isDouble ) - return decodeDouble( token ); - // Attempts to parse the number as an integer. If the number is - // larger than the maximum supported value of an integer then - // we decode the number as a double. - Location current = token.start_; - bool isNegative = *current == '-'; - if ( isNegative ) - ++current; - Value::LargestUInt maxIntegerValue = isNegative ? Value::LargestUInt(-Value::minLargestInt) - : Value::maxLargestUInt; - Value::LargestUInt threshold = maxIntegerValue / 10; - Value::UInt lastDigitThreshold = Value::UInt( maxIntegerValue % 10 ); - assert( lastDigitThreshold >=0 && lastDigitThreshold <= 9 ); - Value::LargestUInt value = 0; - while ( current < token.end_ ) - { - Char c = *current++; - if ( c < '0' || c > '9' ) - return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); - Value::UInt digit(c - '0'); - if ( value >= threshold ) - { - // If the current digit is not the last one, or if it is - // greater than the last digit of the maximum integer value, - // the parse the number as a double. - if ( current != token.end_ || digit > lastDigitThreshold ) - { - return decodeDouble( token ); - } - } - value = value * 10 + digit; - } - if ( isNegative ) - currentValue() = -Value::LargestInt( value ); - else if ( value <= Value::LargestUInt(Value::maxInt) ) - currentValue() = Value::LargestInt( value ); - else - currentValue() = value; - return true; -} - - -bool -Reader::decodeDouble( Token &token ) -{ - double value = 0; - const int bufferSize = 32; - int count; - int length = int(token.end_ - token.start_); - if ( length <= bufferSize ) - { - Char buffer[bufferSize+1]; - memcpy( buffer, token.start_, length ); - buffer[length] = 0; - count = sscanf( buffer, "%lf", &value ); - } - else - { - std::string buffer( token.start_, token.end_ ); - count = sscanf( buffer.c_str(), "%lf", &value ); - } - - if ( count != 1 ) - return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); - currentValue() = value; - return true; -} - - -bool -Reader::decodeString( Token &token ) -{ - std::string decoded; - if ( !decodeString( token, decoded ) ) - return false; - currentValue() = decoded; - return true; -} - - -bool -Reader::decodeString( Token &token, std::string &decoded ) -{ - decoded.reserve( token.end_ - token.start_ - 2 ); - Location current = token.start_ + 1; // skip '"' - Location end = token.end_ - 1; // do not include '"' - while ( current != end ) - { - Char c = *current++; - if ( c == '"' ) - break; - else if ( c == '\\' ) - { - if ( current == end ) - return addError( "Empty escape sequence in string", token, current ); - Char escape = *current++; - switch ( escape ) - { - case '"': decoded += '"'; break; - case '/': decoded += '/'; break; - case '\\': decoded += '\\'; break; - case 'b': decoded += '\b'; break; - case 'f': decoded += '\f'; break; - case 'n': decoded += '\n'; break; - case 'r': decoded += '\r'; break; - case 't': decoded += '\t'; break; - case 'u': - { - unsigned int unicode; - if ( !decodeUnicodeCodePoint( token, current, end, unicode ) ) - return false; - decoded += codePointToUTF8(unicode); - } - break; - default: - return addError( "Bad escape sequence in string", token, current ); - } - } - else - { - decoded += c; - } - } - return true; -} - -bool -Reader::decodeUnicodeCodePoint( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ) -{ - - if ( !decodeUnicodeEscapeSequence( token, current, end, unicode ) ) - return false; - if (unicode >= 0xD800 && unicode <= 0xDBFF) - { - // surrogate pairs - if (end - current < 6) - return addError( "additional six characters expected to parse unicode surrogate pair.", token, current ); - unsigned int surrogatePair; - if (*(current++) == '\\' && *(current++)== 'u') - { - if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair )) - { - unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); - } - else - return false; - } - else - return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current ); - } - return true; -} - -bool -Reader::decodeUnicodeEscapeSequence( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ) -{ - if ( end - current < 4 ) - return addError( "Bad unicode escape sequence in string: four digits expected.", token, current ); - unicode = 0; - for ( int index =0; index < 4; ++index ) - { - Char c = *current++; - unicode *= 16; - if ( c >= '0' && c <= '9' ) - unicode += c - '0'; - else if ( c >= 'a' && c <= 'f' ) - unicode += c - 'a' + 10; - else if ( c >= 'A' && c <= 'F' ) - unicode += c - 'A' + 10; - else - return addError( "Bad unicode escape sequence in string: hexadecimal digit expected.", token, current ); - } - return true; -} - - -bool -Reader::addError( const std::string &message, - Token &token, - Location extra ) -{ - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = extra; - errors_.push_back( info ); - return false; -} - - -bool -Reader::recoverFromError( TokenType skipUntilToken ) -{ - int errorCount = int(errors_.size()); - Token skip; - for (;;) - { - if ( !readToken(skip) ) - errors_.resize( errorCount ); // discard errors caused by recovery - if ( skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream ) - break; - } - errors_.resize( errorCount ); - return false; -} - - -bool -Reader::addErrorAndRecover( const std::string &message, - Token &token, - TokenType skipUntilToken ) -{ - addError( message, token ); - return recoverFromError( skipUntilToken ); -} - - -Value & -Reader::currentValue() -{ - return *(nodes_.top()); -} - - -Reader::Char -Reader::getNextChar() -{ - if ( current_ == end_ ) - return 0; - return *current_++; -} - - -void -Reader::getLocationLineAndColumn( Location location, - int &line, - int &column ) const -{ - Location current = begin_; - Location lastLineStart = current; - line = 0; - while ( current < location && current != end_ ) - { - Char c = *current++; - if ( c == '\r' ) - { - if ( *current == '\n' ) - ++current; - lastLineStart = current; - ++line; - } - else if ( c == '\n' ) - { - lastLineStart = current; - ++line; - } - } - // column & line start at 1 - column = int(location - lastLineStart) + 1; - ++line; -} - - -std::string -Reader::getLocationLineAndColumn( Location location ) const -{ - int line, column; - getLocationLineAndColumn( location, line, column ); - char buffer[18+16+16+1]; - sprintf( buffer, "Line %d, Column %d", line, column ); - return buffer; -} - - -// Deprecated. Preserved for backward compatibility -std::string -Reader::getFormatedErrorMessages() const -{ - return getFormattedErrorMessages(); -} - - -std::string -Reader::getFormattedErrorMessages() const -{ - std::string formattedMessage; - for ( Errors::const_iterator itError = errors_.begin(); - itError != errors_.end(); - ++itError ) - { - const ErrorInfo &error = *itError; - formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n"; - formattedMessage += " " + error.message_ + "\n"; - if ( error.extra_ ) - formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n"; - } - return formattedMessage; -} - - -std::istream& operator>>( std::istream &sin, Value &root ) -{ - Json::Reader reader; - bool ok = reader.parse(sin, root, true); - //JSON_ASSERT( ok ); - if (!ok) throw std::runtime_error(reader.getFormattedErrorMessages()); - return sin; -} - - -} // namespace Json diff --git a/dependencies/build/jsoncpp/json_tool.h b/dependencies/build/jsoncpp/json_tool.h deleted file mode 100644 index 658031bb..00000000 --- a/dependencies/build/jsoncpp/json_tool.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED -# define LIB_JSONCPP_JSON_TOOL_H_INCLUDED - -/* This header provides common string manipulation support, such as UTF-8, - * portable conversion from/to string... - * - * It is an internal header that must not be exposed. - */ - -namespace Json { - -/// Converts a unicode code-point to UTF-8. -static inline std::string -codePointToUTF8(unsigned int cp) -{ - std::string result; - - // based on description from http://en.wikipedia.org/wiki/UTF-8 - - if (cp <= 0x7f) - { - result.resize(1); - result[0] = static_cast(cp); - } - else if (cp <= 0x7FF) - { - result.resize(2); - result[1] = static_cast(0x80 | (0x3f & cp)); - result[0] = static_cast(0xC0 | (0x1f & (cp >> 6))); - } - else if (cp <= 0xFFFF) - { - result.resize(3); - result[2] = static_cast(0x80 | (0x3f & cp)); - result[1] = 0x80 | static_cast((0x3f & (cp >> 6))); - result[0] = 0xE0 | static_cast((0xf & (cp >> 12))); - } - else if (cp <= 0x10FFFF) - { - result.resize(4); - result[3] = static_cast(0x80 | (0x3f & cp)); - result[2] = static_cast(0x80 | (0x3f & (cp >> 6))); - result[1] = static_cast(0x80 | (0x3f & (cp >> 12))); - result[0] = static_cast(0xF0 | (0x7 & (cp >> 18))); - } - - return result; -} - - -/// Returns true if ch is a control character (in range [0,32[). -static inline bool -isControlCharacter(char ch) -{ - return ch > 0 && ch <= 0x1F; -} - - -enum { - /// Constant that specify the size of the buffer that must be passed to uintToString. - uintToStringBufferSize = 3*sizeof(LargestUInt)+1 -}; - -// Defines a char buffer for use with uintToString(). -typedef char UIntToStringBuffer[uintToStringBufferSize]; - - -/** Converts an unsigned integer to string. - * @param value Unsigned interger to convert to string - * @param current Input/Output string buffer. - * Must have at least uintToStringBufferSize chars free. - */ -static inline void -uintToString( LargestUInt value, - char *¤t ) -{ - *--current = 0; - do - { - *--current = char(value % 10) + '0'; - value /= 10; - } - while ( value != 0 ); -} - -} // namespace Json { - -#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED diff --git a/dependencies/build/jsoncpp/json_value.cpp b/dependencies/build/jsoncpp/json_value.cpp deleted file mode 100644 index ff98f635..00000000 --- a/dependencies/build/jsoncpp/json_value.cpp +++ /dev/null @@ -1,1829 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#if !defined(JSON_IS_AMALGAMATION) -# include -# include -# ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -# include "json_batchallocator.h" -# endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR -#endif // if !defined(JSON_IS_AMALGAMATION) -#include -#include -#include -#include -#include -#ifdef JSON_USE_CPPTL -# include -#endif -#include // size_t - -#define JSON_ASSERT_UNREACHABLE assert( false ) -#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw -#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); -#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) JSON_FAIL_MESSAGE( message ) - -namespace Json { - -const Value Value::null; -const Int Value::minInt = Int( ~(UInt(-1)/2) ); -const Int Value::maxInt = Int( UInt(-1)/2 ); -const UInt Value::maxUInt = UInt(-1); -const Int64 Value::minInt64 = Int64( ~(UInt64(-1)/2) ); -const Int64 Value::maxInt64 = Int64( UInt64(-1)/2 ); -const UInt64 Value::maxUInt64 = UInt64(-1); -const LargestInt Value::minLargestInt = LargestInt( ~(LargestUInt(-1)/2) ); -const LargestInt Value::maxLargestInt = LargestInt( LargestUInt(-1)/2 ); -const LargestUInt Value::maxLargestUInt = LargestUInt(-1); - - -/// Unknown size marker -static const unsigned int unknown = (unsigned)-1; - - -/** Duplicates the specified string value. - * @param value Pointer to the string to duplicate. Must be zero-terminated if - * length is "unknown". - * @param length Length of the value. if equals to unknown, then it will be - * computed using strlen(value). - * @return Pointer on the duplicate instance of string. - */ -static inline char * -duplicateStringValue( const char *value, - unsigned int length = unknown ) -{ - if ( length == unknown ) - length = (unsigned int)strlen(value); - char *newString = static_cast( malloc( length + 1 ) ); - JSON_ASSERT_MESSAGE( newString != 0, "Failed to allocate string value buffer" ); - memcpy( newString, value, length ); - newString[length] = 0; - return newString; -} - - -/** Free the string duplicated by duplicateStringValue(). - */ -static inline void -releaseStringValue( char *value ) -{ - if ( value ) - free( value ); -} - -} // namespace Json - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ValueInternals... -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -#if !defined(JSON_IS_AMALGAMATION) -# ifdef JSON_VALUE_USE_INTERNAL_MAP -# include "json_internalarray.inl" -# include "json_internalmap.inl" -# endif // JSON_VALUE_USE_INTERNAL_MAP - -# include "json_valueiterator.inl" -#endif // if !defined(JSON_IS_AMALGAMATION) - -namespace Json { - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::CommentInfo -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - - -Value::CommentInfo::CommentInfo() - : comment_( 0 ) -{ -} - -Value::CommentInfo::~CommentInfo() -{ - if ( comment_ ) - releaseStringValue( comment_ ); -} - - -void -Value::CommentInfo::setComment( const char *text ) -{ - if ( comment_ ) - releaseStringValue( comment_ ); - JSON_ASSERT( text != 0 ); - JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); - // It seems that /**/ style comments are acceptable as well. - comment_ = duplicateStringValue( text ); -} - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::CZString -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -# ifndef JSON_VALUE_USE_INTERNAL_MAP - -// Notes: index_ indicates if the string was allocated when -// a string is stored. - -Value::CZString::CZString( ArrayIndex index ) - : cstr_( 0 ) - , index_( index ) -{ -} - -Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) - : cstr_( allocate == duplicate ? duplicateStringValue(cstr) - : cstr ) - , index_( allocate ) -{ -} - -Value::CZString::CZString( const CZString &other ) -: cstr_( other.index_ != noDuplication && other.cstr_ != 0 - ? duplicateStringValue( other.cstr_ ) - : other.cstr_ ) - , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) - : other.index_ ) -{ -} - -Value::CZString::~CZString() -{ - if ( cstr_ && index_ == duplicate ) - releaseStringValue( const_cast( cstr_ ) ); -} - -void -Value::CZString::swap( CZString &other ) -{ - std::swap( cstr_, other.cstr_ ); - std::swap( index_, other.index_ ); -} - -Value::CZString & -Value::CZString::operator =( const CZString &other ) -{ - CZString temp( other ); - swap( temp ); - return *this; -} - -bool -Value::CZString::operator<( const CZString &other ) const -{ - if ( cstr_ ) - return strcmp( cstr_, other.cstr_ ) < 0; - return index_ < other.index_; -} - -bool -Value::CZString::operator==( const CZString &other ) const -{ - if ( cstr_ ) - return strcmp( cstr_, other.cstr_ ) == 0; - return index_ == other.index_; -} - - -ArrayIndex -Value::CZString::index() const -{ - return index_; -} - - -const char * -Value::CZString::c_str() const -{ - return cstr_; -} - -bool -Value::CZString::isStaticString() const -{ - return index_ == noDuplication; -} - -#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class Value::Value -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -/*! \internal Default constructor initialization must be equivalent to: - * memset( this, 0, sizeof(Value) ) - * This optimization is used in ValueInternalMap fast allocator. - */ -Value::Value( ValueType type ) - : type_( type ) - , allocated_( 0 ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - switch ( type ) - { - case nullValue: - break; - case intValue: - case uintValue: - value_.int_ = 0; - break; - case realValue: - value_.real_ = 0.0; - break; - case stringValue: - value_.string_ = 0; - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - value_.map_ = new ObjectValues(); - break; -#else - case arrayValue: - value_.array_ = arrayAllocator()->newArray(); - break; - case objectValue: - value_.map_ = mapAllocator()->newMap(); - break; -#endif - case booleanValue: - value_.bool_ = false; - break; - default: - JSON_ASSERT_UNREACHABLE; - } -} - - -#if defined(JSON_HAS_INT64) -Value::Value( UInt value ) - : type_( uintValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.uint_ = value; -} - -Value::Value( Int value ) - : type_( intValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.int_ = value; -} - -#endif // if defined(JSON_HAS_INT64) - - -Value::Value( Int64 value ) - : type_( intValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.int_ = value; -} - - -Value::Value( UInt64 value ) - : type_( uintValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.uint_ = value; -} - -Value::Value( double value ) - : type_( realValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.real_ = value; -} - -Value::Value( const char *value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value ); -} - - -Value::Value( const char *beginValue, - const char *endValue ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( beginValue, - (unsigned int)(endValue - beginValue) ); -} - - -Value::Value( const std::string &value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value.c_str(), - (unsigned int)value.length() ); - -} - -Value::Value( const StaticString &value ) - : type_( stringValue ) - , allocated_( false ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = const_cast( value.c_str() ); -} - - -# ifdef JSON_USE_CPPTL -Value::Value( const CppTL::ConstString &value ) - : type_( stringValue ) - , allocated_( true ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.string_ = duplicateStringValue( value, value.length() ); -} -# endif - -Value::Value( bool value ) - : type_( booleanValue ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - value_.bool_ = value; -} - - -Value::Value( const Value &other ) - : type_( other.type_ ) - , comments_( 0 ) -# ifdef JSON_VALUE_USE_INTERNAL_MAP - , itemIsUsed_( 0 ) -#endif -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - value_ = other.value_; - break; - case stringValue: - if ( other.value_.string_ ) - { - value_.string_ = duplicateStringValue( other.value_.string_ ); - allocated_ = true; - } - else - value_.string_ = 0; - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - value_.map_ = new ObjectValues( *other.value_.map_ ); - break; -#else - case arrayValue: - value_.array_ = arrayAllocator()->newArrayCopy( *other.value_.array_ ); - break; - case objectValue: - value_.map_ = mapAllocator()->newMapCopy( *other.value_.map_ ); - break; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - if ( other.comments_ ) - { - comments_ = new CommentInfo[numberOfCommentPlacement]; - for ( int comment =0; comment < numberOfCommentPlacement; ++comment ) - { - const CommentInfo &otherComment = other.comments_[comment]; - if ( otherComment.comment_ ) - comments_[comment].setComment( otherComment.comment_ ); - } - } -} - - -Value::~Value() -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - break; - case stringValue: - if ( allocated_ ) - releaseStringValue( value_.string_ ); - break; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - delete value_.map_; - break; -#else - case arrayValue: - arrayAllocator()->destructArray( value_.array_ ); - break; - case objectValue: - mapAllocator()->destructMap( value_.map_ ); - break; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - - if ( comments_ ) - delete[] comments_; -} - -Value & -Value::operator=( const Value &other ) -{ - Value temp( other ); - swap( temp ); - return *this; -} - -void -Value::swap( Value &other ) -{ - ValueType temp = type_; - type_ = other.type_; - other.type_ = temp; - std::swap( value_, other.value_ ); - int temp2 = allocated_; - allocated_ = other.allocated_; - other.allocated_ = temp2; -} - -ValueType -Value::type() const -{ - return type_; -} - - -int -Value::compare( const Value &other ) const -{ - if ( *this < other ) - return -1; - if ( *this > other ) - return 1; - return 0; -} - - -bool -Value::operator <( const Value &other ) const -{ - int typeDelta = type_ - other.type_; - if ( typeDelta ) - return typeDelta < 0 ? true : false; - switch ( type_ ) - { - case nullValue: - return false; - case intValue: - return value_.int_ < other.value_.int_; - case uintValue: - return value_.uint_ < other.value_.uint_; - case realValue: - return value_.real_ < other.value_.real_; - case booleanValue: - return value_.bool_ < other.value_.bool_; - case stringValue: - return ( value_.string_ == 0 && other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ - && strcmp( value_.string_, other.value_.string_ ) < 0 ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - { - int delta = int( value_.map_->size() - other.value_.map_->size() ); - if ( delta ) - return delta < 0; - return (*value_.map_) < (*other.value_.map_); - } -#else - case arrayValue: - return value_.array_->compare( *(other.value_.array_) ) < 0; - case objectValue: - return value_.map_->compare( *(other.value_.map_) ) < 0; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable -} - -bool -Value::operator <=( const Value &other ) const -{ - return !(other < *this); -} - -bool -Value::operator >=( const Value &other ) const -{ - return !(*this < other); -} - -bool -Value::operator >( const Value &other ) const -{ - return other < *this; -} - -bool -Value::operator ==( const Value &other ) const -{ - //if ( type_ != other.type_ ) - // GCC 2.95.3 says: - // attempt to take address of bit-field structure member `Json::Value::type_' - // Beats me, but a temp solves the problem. - int temp = other.type_; - if ( type_ != temp ) - return false; - switch ( type_ ) - { - case nullValue: - return true; - case intValue: - return value_.int_ == other.value_.int_; - case uintValue: - return value_.uint_ == other.value_.uint_; - case realValue: - return value_.real_ == other.value_.real_; - case booleanValue: - return value_.bool_ == other.value_.bool_; - case stringValue: - return ( value_.string_ == other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ - && strcmp( value_.string_, other.value_.string_ ) == 0 ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - return value_.map_->size() == other.value_.map_->size() - && (*value_.map_) == (*other.value_.map_); -#else - case arrayValue: - return value_.array_->compare( *(other.value_.array_) ) == 0; - case objectValue: - return value_.map_->compare( *(other.value_.map_) ) == 0; -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable -} - -bool -Value::operator !=( const Value &other ) const -{ - return !( *this == other ); -} - -const char * -Value::asCString() const -{ - JSON_ASSERT( type_ == stringValue ); - return value_.string_; -} - - -std::string -Value::asString() const -{ - switch ( type_ ) - { - case nullValue: - return ""; - case stringValue: - return value_.string_ ? value_.string_ : ""; - case booleanValue: - return value_.bool_ ? "true" : "false"; - case intValue: - case uintValue: - case realValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to string" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return ""; // unreachable -} - -# ifdef JSON_USE_CPPTL -CppTL::ConstString -Value::asConstString() const -{ - return CppTL::ConstString( asString().c_str() ); -} -# endif - - -Value::Int -Value::asInt() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= minInt && value_.int_ <= maxInt, "unsigned integer out of signed int range" ); - return Int(value_.int_); - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= UInt(maxInt), "unsigned integer out of signed int range" ); - return Int(value_.uint_); - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); - return Int( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to int" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -Value::UInt -Value::asUInt() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); - JSON_ASSERT_MESSAGE( value_.int_ <= maxUInt, "signed integer out of UInt range" ); - return UInt(value_.int_); - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= maxUInt, "unsigned integer out of UInt range" ); - return UInt(value_.uint_); - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); - return UInt( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to uint" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -# if defined(JSON_HAS_INT64) - -Value::Int64 -Value::asInt64() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - return value_.int_; - case uintValue: - JSON_ASSERT_MESSAGE( value_.uint_ <= UInt64(maxInt64), "unsigned integer out of Int64 range" ); - return value_.uint_; - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= minInt64 && value_.real_ <= maxInt64, "Real out of Int64 range" ); - return Int( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to Int64" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -Value::UInt64 -Value::asUInt64() const -{ - switch ( type_ ) - { - case nullValue: - return 0; - case intValue: - JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to UInt64" ); - return value_.int_; - case uintValue: - return value_.uint_; - case realValue: - JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt64, "Real out of UInt64 range" ); - return UInt( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1 : 0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to UInt64" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} -# endif // if defined(JSON_HAS_INT64) - - -LargestInt -Value::asLargestInt() const -{ -#if defined(JSON_NO_INT64) - return asInt(); -#else - return asInt64(); -#endif -} - - -LargestUInt -Value::asLargestUInt() const -{ -#if defined(JSON_NO_INT64) - return asUInt(); -#else - return asUInt64(); -#endif -} - - -double -Value::asDouble() const -{ - switch ( type_ ) - { - case nullValue: - return 0.0; - case intValue: - return static_cast( value_.int_ ); - case uintValue: -#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( value_.uint_ ); -#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1); -#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: - return value_.real_; - case booleanValue: - return value_.bool_ ? 1.0 : 0.0; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to double" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - -float -Value::asFloat() const -{ - switch ( type_ ) - { - case nullValue: - return 0.0f; - case intValue: - return static_cast( value_.int_ ); - case uintValue: -#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( value_.uint_ ); -#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1); -#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - case realValue: - return static_cast( value_.real_ ); - case booleanValue: - return value_.bool_ ? 1.0f : 0.0f; - case stringValue: - case arrayValue: - case objectValue: - JSON_FAIL_MESSAGE( "Type is not convertible to float" ); - default: - JSON_ASSERT_UNREACHABLE; - } - return 0.0f; // unreachable; -} - -bool -Value::asBool() const -{ - switch ( type_ ) - { - case nullValue: - return false; - case intValue: - case uintValue: - return value_.int_ != 0; - case realValue: - return value_.real_ != 0.0; - case booleanValue: - return value_.bool_; - case stringValue: - return value_.string_ && value_.string_[0] != 0; - case arrayValue: - case objectValue: - return value_.map_->size() != 0; - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable; -} - - -bool -Value::isConvertibleTo( ValueType other ) const -{ - switch ( type_ ) - { - case nullValue: - return true; - case intValue: - return ( other == nullValue && value_.int_ == 0 ) - || other == intValue - || ( other == uintValue && value_.int_ >= 0 ) - || other == realValue - || other == stringValue - || other == booleanValue; - case uintValue: - return ( other == nullValue && value_.uint_ == 0 ) - || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) - || other == uintValue - || other == realValue - || other == stringValue - || other == booleanValue; - case realValue: - return ( other == nullValue && value_.real_ == 0.0 ) - || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) - || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) - || other == realValue - || other == stringValue - || other == booleanValue; - case booleanValue: - return ( other == nullValue && value_.bool_ == false ) - || other == intValue - || other == uintValue - || other == realValue - || other == stringValue - || other == booleanValue; - case stringValue: - return other == stringValue - || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); - case arrayValue: - return other == arrayValue - || ( other == nullValue && value_.map_->size() == 0 ); - case objectValue: - return other == objectValue - || ( other == nullValue && value_.map_->size() == 0 ); - default: - JSON_ASSERT_UNREACHABLE; - } - return false; // unreachable; -} - - -/// Number of values in array or object -ArrayIndex -Value::size() const -{ - switch ( type_ ) - { - case nullValue: - case intValue: - case uintValue: - case realValue: - case booleanValue: - case stringValue: - return 0; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: // size of the array is highest index + 1 - if ( !value_.map_->empty() ) - { - ObjectValues::const_iterator itLast = value_.map_->end(); - --itLast; - return (*itLast).first.index()+1; - } - return 0; - case objectValue: - return ArrayIndex( value_.map_->size() ); -#else - case arrayValue: - return Int( value_.array_->size() ); - case objectValue: - return Int( value_.map_->size() ); -#endif - default: - JSON_ASSERT_UNREACHABLE; - } - return 0; // unreachable; -} - - -bool -Value::empty() const -{ - if ( isNull() || isArray() || isObject() ) - return size() == 0u; - else - return false; -} - - -bool -Value::operator!() const -{ - return isNull(); -} - - -void -Value::clear() -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); - - switch ( type_ ) - { -#ifndef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - case objectValue: - value_.map_->clear(); - break; -#else - case arrayValue: - value_.array_->clear(); - break; - case objectValue: - value_.map_->clear(); - break; -#endif - default: - break; - } -} - -void -Value::resize( ArrayIndex newSize ) -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - *this = Value( arrayValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - ArrayIndex oldSize = size(); - if ( newSize == 0 ) - clear(); - else if ( newSize > oldSize ) - (*this)[ newSize - 1 ]; - else - { - for ( ArrayIndex index = newSize; index < oldSize; ++index ) - { - value_.map_->erase( index ); - } - assert( size() == newSize ); - } -#else - value_.array_->resize( newSize ); -#endif -} - - -Value & -Value::operator[]( ArrayIndex index ) -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - *this = Value( arrayValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString key( index ); - ObjectValues::iterator it = value_.map_->lower_bound( key ); - if ( it != value_.map_->end() && (*it).first == key ) - return (*it).second; - - ObjectValues::value_type defaultValue( key, null ); - it = value_.map_->insert( it, defaultValue ); - return (*it).second; -#else - return value_.array_->resolveReference( index ); -#endif -} - - -Value & -Value::operator[]( int index ) -{ - JSON_ASSERT( index >= 0 ); - return (*this)[ ArrayIndex(index) ]; -} - - -const Value & -Value::operator[]( ArrayIndex index ) const -{ - JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); - if ( type_ == nullValue ) - return null; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString key( index ); - ObjectValues::const_iterator it = value_.map_->find( key ); - if ( it == value_.map_->end() ) - return null; - return (*it).second; -#else - Value *value = value_.array_->find( index ); - return value ? *value : null; -#endif -} - - -const Value & -Value::operator[]( int index ) const -{ - JSON_ASSERT( index >= 0 ); - return (*this)[ ArrayIndex(index) ]; -} - - -Value & -Value::operator[]( const char *key ) -{ - return resolveReference( key, false ); -} - - -Value & -Value::resolveReference( const char *key, - bool isStatic ) -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - *this = Value( objectValue ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString actualKey( key, isStatic ? CZString::noDuplication - : CZString::duplicateOnCopy ); - ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); - if ( it != value_.map_->end() && (*it).first == actualKey ) - return (*it).second; - - ObjectValues::value_type defaultValue( actualKey, null ); - it = value_.map_->insert( it, defaultValue ); - Value &value = (*it).second; - return value; -#else - return value_.map_->resolveReference( key, isStatic ); -#endif -} - - -Value -Value::get( ArrayIndex index, - const Value &defaultValue ) const -{ - const Value *value = &((*this)[index]); - return value == &null ? defaultValue : *value; -} - - -bool -Value::isValidIndex( ArrayIndex index ) const -{ - return index < size(); -} - - - -const Value & -Value::operator[]( const char *key ) const -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - return null; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString actualKey( key, CZString::noDuplication ); - ObjectValues::const_iterator it = value_.map_->find( actualKey ); - if ( it == value_.map_->end() ) - return null; - return (*it).second; -#else - const Value *value = value_.map_->find( key ); - return value ? *value : null; -#endif -} - - -Value & -Value::operator[]( const std::string &key ) -{ - return (*this)[ key.c_str() ]; -} - - -const Value & -Value::operator[]( const std::string &key ) const -{ - return (*this)[ key.c_str() ]; -} - -Value & -Value::operator[]( const StaticString &key ) -{ - return resolveReference( key, true ); -} - - -# ifdef JSON_USE_CPPTL -Value & -Value::operator[]( const CppTL::ConstString &key ) -{ - return (*this)[ key.c_str() ]; -} - - -const Value & -Value::operator[]( const CppTL::ConstString &key ) const -{ - return (*this)[ key.c_str() ]; -} -# endif - - -Value & -Value::append( const Value &value ) -{ - return (*this)[size()] = value; -} - - -Value -Value::get( const char *key, - const Value &defaultValue ) const -{ - const Value *value = &((*this)[key]); - return value == &null ? defaultValue : *value; -} - - -Value -Value::get( const std::string &key, - const Value &defaultValue ) const -{ - return get( key.c_str(), defaultValue ); -} - -Value -Value::removeMember( const char* key ) -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - return null; -#ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString actualKey( key, CZString::noDuplication ); - ObjectValues::iterator it = value_.map_->find( actualKey ); - if ( it == value_.map_->end() ) - return null; - Value old(it->second); - value_.map_->erase(it); - return old; -#else - Value *value = value_.map_->find( key ); - if (value){ - Value old(*value); - value_.map_.remove( key ); - return old; - } else { - return null; - } -#endif -} - -Value -Value::removeMember( const std::string &key ) -{ - return removeMember( key.c_str() ); -} - -# ifdef JSON_USE_CPPTL -Value -Value::get( const CppTL::ConstString &key, - const Value &defaultValue ) const -{ - return get( key.c_str(), defaultValue ); -} -# endif - -bool -Value::isMember( const char *key ) const -{ - const Value *value = &((*this)[key]); - return value != &null; -} - - -bool -Value::isMember( const std::string &key ) const -{ - return isMember( key.c_str() ); -} - - -# ifdef JSON_USE_CPPTL -bool -Value::isMember( const CppTL::ConstString &key ) const -{ - return isMember( key.c_str() ); -} -#endif - -Value::Members -Value::getMemberNames() const -{ - JSON_ASSERT( type_ == nullValue || type_ == objectValue ); - if ( type_ == nullValue ) - return Value::Members(); - Members members; - members.reserve( value_.map_->size() ); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - ObjectValues::const_iterator it = value_.map_->begin(); - ObjectValues::const_iterator itEnd = value_.map_->end(); - for ( ; it != itEnd; ++it ) - members.push_back( std::string( (*it).first.c_str() ) ); -#else - ValueInternalMap::IteratorState it; - ValueInternalMap::IteratorState itEnd; - value_.map_->makeBeginIterator( it ); - value_.map_->makeEndIterator( itEnd ); - for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) ) - members.push_back( std::string( ValueInternalMap::key( it ) ) ); -#endif - return members; -} -// -//# ifdef JSON_USE_CPPTL -//EnumMemberNames -//Value::enumMemberNames() const -//{ -// if ( type_ == objectValue ) -// { -// return CppTL::Enum::any( CppTL::Enum::transform( -// CppTL::Enum::keys( *(value_.map_), CppTL::Type() ), -// MemberNamesTransform() ) ); -// } -// return EnumMemberNames(); -//} -// -// -//EnumValues -//Value::enumValues() const -//{ -// if ( type_ == objectValue || type_ == arrayValue ) -// return CppTL::Enum::anyValues( *(value_.map_), -// CppTL::Type() ); -// return EnumValues(); -//} -// -//# endif - - -bool -Value::isNull() const -{ - return type_ == nullValue; -} - - -bool -Value::isBool() const -{ - return type_ == booleanValue; -} - - -bool -Value::isInt() const -{ - return type_ == intValue; -} - - -bool -Value::isUInt() const -{ - return type_ == uintValue; -} - - -bool -Value::isIntegral() const -{ - return type_ == intValue - || type_ == uintValue - || type_ == booleanValue; -} - - -bool -Value::isDouble() const -{ - return type_ == realValue; -} - - -bool -Value::isNumeric() const -{ - return isIntegral() || isDouble(); -} - - -bool -Value::isString() const -{ - return type_ == stringValue; -} - - -bool -Value::isArray() const -{ - return type_ == nullValue || type_ == arrayValue; -} - - -bool -Value::isObject() const -{ - return type_ == nullValue || type_ == objectValue; -} - - -void -Value::setComment( const char *comment, - CommentPlacement placement ) -{ - if ( !comments_ ) - comments_ = new CommentInfo[numberOfCommentPlacement]; - comments_[placement].setComment( comment ); -} - - -void -Value::setComment( const std::string &comment, - CommentPlacement placement ) -{ - setComment( comment.c_str(), placement ); -} - - -bool -Value::hasComment( CommentPlacement placement ) const -{ - return comments_ != 0 && comments_[placement].comment_ != 0; -} - -std::string -Value::getComment( CommentPlacement placement ) const -{ - if ( hasComment(placement) ) - return comments_[placement].comment_; - return ""; -} - - -std::string -Value::toStyledString() const -{ - StyledWriter writer; - return writer.write( *this ); -} - - -Value::const_iterator -Value::begin() const -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeBeginIterator( it ); - return const_iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeBeginIterator( it ); - return const_iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return const_iterator( value_.map_->begin() ); - break; -#endif - default: - break; - } - return const_iterator(); -} - -Value::const_iterator -Value::end() const -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeEndIterator( it ); - return const_iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeEndIterator( it ); - return const_iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return const_iterator( value_.map_->end() ); - break; -#endif - default: - break; - } - return const_iterator(); -} - - -Value::iterator -Value::begin() -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeBeginIterator( it ); - return iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeBeginIterator( it ); - return iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return iterator( value_.map_->begin() ); - break; -#endif - default: - break; - } - return iterator(); -} - -Value::iterator -Value::end() -{ - switch ( type_ ) - { -#ifdef JSON_VALUE_USE_INTERNAL_MAP - case arrayValue: - if ( value_.array_ ) - { - ValueInternalArray::IteratorState it; - value_.array_->makeEndIterator( it ); - return iterator( it ); - } - break; - case objectValue: - if ( value_.map_ ) - { - ValueInternalMap::IteratorState it; - value_.map_->makeEndIterator( it ); - return iterator( it ); - } - break; -#else - case arrayValue: - case objectValue: - if ( value_.map_ ) - return iterator( value_.map_->end() ); - break; -#endif - default: - break; - } - return iterator(); -} - - -// class PathArgument -// ////////////////////////////////////////////////////////////////// - -PathArgument::PathArgument() - : kind_( kindNone ) -{ -} - - -PathArgument::PathArgument( ArrayIndex index ) - : index_( index ) - , kind_( kindIndex ) -{ -} - - -PathArgument::PathArgument( const char *key ) - : key_( key ) - , kind_( kindKey ) -{ -} - - -PathArgument::PathArgument( const std::string &key ) - : key_( key.c_str() ) - , kind_( kindKey ) -{ -} - -// class Path -// ////////////////////////////////////////////////////////////////// - -Path::Path( const std::string &path, - const PathArgument &a1, - const PathArgument &a2, - const PathArgument &a3, - const PathArgument &a4, - const PathArgument &a5 ) -{ - InArgs in; - in.push_back( &a1 ); - in.push_back( &a2 ); - in.push_back( &a3 ); - in.push_back( &a4 ); - in.push_back( &a5 ); - makePath( path, in ); -} - - -void -Path::makePath( const std::string &path, - const InArgs &in ) -{ - const char *current = path.c_str(); - const char *end = current + path.length(); - InArgs::const_iterator itInArg = in.begin(); - while ( current != end ) - { - if ( *current == '[' ) - { - ++current; - if ( *current == '%' ) - addPathInArg( path, in, itInArg, PathArgument::kindIndex ); - else - { - ArrayIndex index = 0; - for ( ; current != end && *current >= '0' && *current <= '9'; ++current ) - index = index * 10 + ArrayIndex(*current - '0'); - args_.push_back( index ); - } - if ( current == end || *current++ != ']' ) - invalidPath( path, int(current - path.c_str()) ); - } - else if ( *current == '%' ) - { - addPathInArg( path, in, itInArg, PathArgument::kindKey ); - ++current; - } - else if ( *current == '.' ) - { - ++current; - } - else - { - const char *beginName = current; - while ( current != end && !strchr( "[.", *current ) ) - ++current; - args_.push_back( std::string( beginName, current ) ); - } - } -} - - -void -Path::addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, - PathArgument::Kind kind ) -{ - if ( itInArg == in.end() ) - { - // Error: missing argument %d - } - else if ( (*itInArg)->kind_ != kind ) - { - // Error: bad argument type - } - else - { - args_.push_back( **itInArg ); - } -} - - -void -Path::invalidPath( const std::string &path, - int location ) -{ - // Error: invalid path. -} - - -const Value & -Path::resolve( const Value &root ) const -{ - const Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) - { - // Error: unable to resolve path (array value expected at position... - } - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - { - // Error: unable to resolve path (object value expected at position...) - } - node = &((*node)[arg.key_]); - if ( node == &Value::null ) - { - // Error: unable to resolve path (object has no member named '' at position...) - } - } - } - return *node; -} - - -Value -Path::resolve( const Value &root, - const Value &defaultValue ) const -{ - const Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) - return defaultValue; - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - return defaultValue; - node = &((*node)[arg.key_]); - if ( node == &Value::null ) - return defaultValue; - } - } - return *node; -} - - -Value & -Path::make( Value &root ) const -{ - Value *node = &root; - for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) - { - const PathArgument &arg = *it; - if ( arg.kind_ == PathArgument::kindIndex ) - { - if ( !node->isArray() ) - { - // Error: node is not an array at position ... - } - node = &((*node)[arg.index_]); - } - else if ( arg.kind_ == PathArgument::kindKey ) - { - if ( !node->isObject() ) - { - // Error: node is not an object at position... - } - node = &((*node)[arg.key_]); - } - } - return *node; -} - - -} // namespace Json diff --git a/dependencies/build/jsoncpp/json_valueiterator.inl b/dependencies/build/jsoncpp/json_valueiterator.inl deleted file mode 100644 index 7457ca38..00000000 --- a/dependencies/build/jsoncpp/json_valueiterator.inl +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -// included by json_value.cpp - -namespace Json { - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class ValueIteratorBase -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -ValueIteratorBase::ValueIteratorBase() -#ifndef JSON_VALUE_USE_INTERNAL_MAP - : current_() - , isNull_( true ) -{ -} -#else - : isArray_( true ) - , isNull_( true ) -{ - iterator_.array_ = ValueInternalArray::IteratorState(); -} -#endif - - -#ifndef JSON_VALUE_USE_INTERNAL_MAP -ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t ) - : current_( current ) - , isNull_( false ) -{ -} -#else -ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state ) - : isArray_( true ) -{ - iterator_.array_ = state; -} - - -ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state ) - : isArray_( false ) -{ - iterator_.map_ = state; -} -#endif - -Value & -ValueIteratorBase::deref() const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - return current_->second; -#else - if ( isArray_ ) - return ValueInternalArray::dereference( iterator_.array_ ); - return ValueInternalMap::value( iterator_.map_ ); -#endif -} - - -void -ValueIteratorBase::increment() -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - ++current_; -#else - if ( isArray_ ) - ValueInternalArray::increment( iterator_.array_ ); - ValueInternalMap::increment( iterator_.map_ ); -#endif -} - - -void -ValueIteratorBase::decrement() -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - --current_; -#else - if ( isArray_ ) - ValueInternalArray::decrement( iterator_.array_ ); - ValueInternalMap::decrement( iterator_.map_ ); -#endif -} - - -ValueIteratorBase::difference_type -ValueIteratorBase::computeDistance( const SelfType &other ) const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP -# ifdef JSON_USE_CPPTL_SMALLMAP - return current_ - other.current_; -# else - // Iterator for null value are initialized using the default - // constructor, which initialize current_ to the default - // std::map::iterator. As begin() and end() are two instance - // of the default std::map::iterator, they can not be compared. - // To allow this, we handle this comparison specifically. - if ( isNull_ && other.isNull_ ) - { - return 0; - } - - - // Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL, - // which is the one used by default). - // Using a portable hand-made version for non random iterator instead: - // return difference_type( std::distance( current_, other.current_ ) ); - difference_type myDistance = 0; - for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it ) - { - ++myDistance; - } - return myDistance; -# endif -#else - if ( isArray_ ) - return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ ); - return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ ); -#endif -} - - -bool -ValueIteratorBase::isEqual( const SelfType &other ) const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - if ( isNull_ ) - { - return other.isNull_; - } - return current_ == other.current_; -#else - if ( isArray_ ) - return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ ); - return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ ); -#endif -} - - -void -ValueIteratorBase::copy( const SelfType &other ) -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - current_ = other.current_; -#else - if ( isArray_ ) - iterator_.array_ = other.iterator_.array_; - iterator_.map_ = other.iterator_.map_; -#endif -} - - -Value -ValueIteratorBase::key() const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - const Value::CZString czstring = (*current_).first; - if ( czstring.c_str() ) - { - if ( czstring.isStaticString() ) - return Value( StaticString( czstring.c_str() ) ); - return Value( czstring.c_str() ); - } - return Value( czstring.index() ); -#else - if ( isArray_ ) - return Value( ValueInternalArray::indexOf( iterator_.array_ ) ); - bool isStatic; - const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic ); - if ( isStatic ) - return Value( StaticString( memberName ) ); - return Value( memberName ); -#endif -} - - -UInt -ValueIteratorBase::index() const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - const Value::CZString czstring = (*current_).first; - if ( !czstring.c_str() ) - return czstring.index(); - return Value::UInt( -1 ); -#else - if ( isArray_ ) - return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) ); - return Value::UInt( -1 ); -#endif -} - - -const char * -ValueIteratorBase::memberName() const -{ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - const char *name = (*current_).first.c_str(); - return name ? name : ""; -#else - if ( !isArray_ ) - return ValueInternalMap::key( iterator_.map_ ); - return ""; -#endif -} - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class ValueConstIterator -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -ValueConstIterator::ValueConstIterator() -{ -} - - -#ifndef JSON_VALUE_USE_INTERNAL_MAP -ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t ) - : ValueIteratorBase( current ) -{ -} -#else -ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state ) - : ValueIteratorBase( state ) -{ -} - -ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state ) - : ValueIteratorBase( state ) -{ -} -#endif - -ValueConstIterator & -ValueConstIterator::operator =( const ValueIteratorBase &other ) -{ - copy( other ); - return *this; -} - - -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// class ValueIterator -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// -// ////////////////////////////////////////////////////////////////// - -ValueIterator::ValueIterator() -{ -} - - -#ifndef JSON_VALUE_USE_INTERNAL_MAP -ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t ) - : ValueIteratorBase( current ) -{ -} -#else -ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state ) - : ValueIteratorBase( state ) -{ -} - -ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state ) - : ValueIteratorBase( state ) -{ -} -#endif - -ValueIterator::ValueIterator( const ValueConstIterator &other ) - : ValueIteratorBase( other ) -{ -} - -ValueIterator::ValueIterator( const ValueIterator &other ) - : ValueIteratorBase( other ) -{ -} - -ValueIterator & -ValueIterator::operator =( const SelfType &other ) -{ - copy( other ); - return *this; -} - -} // namespace Json diff --git a/dependencies/build/jsoncpp/json_writer.cpp b/dependencies/build/jsoncpp/json_writer.cpp deleted file mode 100644 index 1bda183f..00000000 --- a/dependencies/build/jsoncpp/json_writer.cpp +++ /dev/null @@ -1,838 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#if !defined(JSON_IS_AMALGAMATION) -# include -# include "json_tool.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -#include -#include -#include -#include -#include -#include -#include - -#if _MSC_VER >= 1400 // VC++ 8.0 -#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. -#endif - -namespace Json { - -static bool containsControlCharacter( const char* str ) -{ - while ( *str ) - { - if ( isControlCharacter( *(str++) ) ) - return true; - } - return false; -} - - -std::string valueToString( LargestInt value ) -{ - UIntToStringBuffer buffer; - char *current = buffer + sizeof(buffer); - bool isNegative = value < 0; - if ( isNegative ) - value = -value; - uintToString( LargestUInt(value), current ); - if ( isNegative ) - *--current = '-'; - assert( current >= buffer ); - return current; -} - - -std::string valueToString( LargestUInt value ) -{ - UIntToStringBuffer buffer; - char *current = buffer + sizeof(buffer); - uintToString( value, current ); - assert( current >= buffer ); - return current; -} - -#if defined(JSON_HAS_INT64) - -std::string valueToString( Int value ) -{ - return valueToString( LargestInt(value) ); -} - - -std::string valueToString( UInt value ) -{ - return valueToString( LargestUInt(value) ); -} - -#endif // # if defined(JSON_HAS_INT64) - - -std::string valueToString( double value ) -{ - char buffer[32]; -#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. - sprintf_s(buffer, sizeof(buffer), "%#.16g", value); -#else - sprintf(buffer, "%#.16g", value); -#endif - char* ch = buffer + strlen(buffer) - 1; - if (*ch != '0') return buffer; // nothing to truncate, so save time - while(ch > buffer && *ch == '0'){ - --ch; - } - char* last_nonzero = ch; - while(ch >= buffer){ - switch(*ch){ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - --ch; - continue; - case '.': - // Truncate zeroes to save bytes in output, but keep one. - *(last_nonzero+2) = '\0'; - return buffer; - default: - return buffer; - } - } - return buffer; -} - - -std::string valueToString( bool value ) -{ - return value ? "true" : "false"; -} - -std::string valueToQuotedString( const char *value ) -{ - // Not sure how to handle unicode... - if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && !containsControlCharacter( value )) - return std::string("\"") + value + "\""; - // We have to walk value and escape any special characters. - // Appending to std::string is not efficient, but this should be rare. - // (Note: forward slashes are *not* rare, but I am not escaping them.) - std::string::size_type maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL - std::string result; - result.reserve(maxsize); // to avoid lots of mallocs - result += "\""; - for (const char* c=value; *c != 0; ++c) - { - switch(*c) - { - case '\"': - result += "\\\""; - break; - case '\\': - result += "\\\\"; - break; - case '\b': - result += "\\b"; - break; - case '\f': - result += "\\f"; - break; - case '\n': - result += "\\n"; - break; - case '\r': - result += "\\r"; - break; - case '\t': - result += "\\t"; - break; - //case '/': - // Even though \/ is considered a legal escape in JSON, a bare - // slash is also legal, so I see no reason to escape it. - // (I hope I am not misunderstanding something. - // blep notes: actually escaping \/ may be useful in javascript to avoid (*c); - result += oss.str(); - } - else - { - result += *c; - } - break; - } - } - result += "\""; - return result; -} - -// Class Writer -// ////////////////////////////////////////////////////////////////// -Writer::~Writer() -{ -} - - -// Class FastWriter -// ////////////////////////////////////////////////////////////////// - -FastWriter::FastWriter() - : yamlCompatiblityEnabled_( false ) -{ -} - - -void -FastWriter::enableYAMLCompatibility() -{ - yamlCompatiblityEnabled_ = true; -} - - -std::string -FastWriter::write( const Value &root ) -{ - document_ = ""; - writeValue( root ); - document_ += "\n"; - return document_; -} - - -void -FastWriter::writeValue( const Value &value ) -{ - switch ( value.type() ) - { - case nullValue: - document_ += "null"; - break; - case intValue: - document_ += valueToString( value.asLargestInt() ); - break; - case uintValue: - document_ += valueToString( value.asLargestUInt() ); - break; - case realValue: - document_ += valueToString( value.asDouble() ); - break; - case stringValue: - document_ += valueToQuotedString( value.asCString() ); - break; - case booleanValue: - document_ += valueToString( value.asBool() ); - break; - case arrayValue: - { - document_ += "["; - int size = value.size(); - for ( int index =0; index < size; ++index ) - { - if ( index > 0 ) - document_ += ","; - writeValue( value[index] ); - } - document_ += "]"; - } - break; - case objectValue: - { - Value::Members members( value.getMemberNames() ); - document_ += "{"; - for ( Value::Members::iterator it = members.begin(); - it != members.end(); - ++it ) - { - const std::string &name = *it; - if ( it != members.begin() ) - document_ += ","; - document_ += valueToQuotedString( name.c_str() ); - document_ += yamlCompatiblityEnabled_ ? ": " - : ":"; - writeValue( value[name] ); - } - document_ += "}"; - } - break; - } -} - - -// Class StyledWriter -// ////////////////////////////////////////////////////////////////// - -StyledWriter::StyledWriter() - : rightMargin_( 74 ) - , indentSize_( 3 ) -{ -} - - -std::string -StyledWriter::write( const Value &root ) -{ - document_ = ""; - addChildValues_ = false; - indentString_ = ""; - writeCommentBeforeValue( root ); - writeValue( root ); - writeCommentAfterValueOnSameLine( root ); - document_ += "\n"; - return document_; -} - - -void -StyledWriter::writeValue( const Value &value ) -{ - switch ( value.type() ) - { - case nullValue: - pushValue( "null" ); - break; - case intValue: - pushValue( valueToString( value.asLargestInt() ) ); - break; - case uintValue: - pushValue( valueToString( value.asLargestUInt() ) ); - break; - case realValue: - pushValue( valueToString( value.asDouble() ) ); - break; - case stringValue: - pushValue( valueToQuotedString( value.asCString() ) ); - break; - case booleanValue: - pushValue( valueToString( value.asBool() ) ); - break; - case arrayValue: - writeArrayValue( value); - break; - case objectValue: - { - Value::Members members( value.getMemberNames() ); - if ( members.empty() ) - pushValue( "{}" ); - else - { - writeWithIndent( "{" ); - indent(); - Value::Members::iterator it = members.begin(); - for (;;) - { - const std::string &name = *it; - const Value &childValue = value[name]; - writeCommentBeforeValue( childValue ); - writeWithIndent( valueToQuotedString( name.c_str() ) ); - document_ += " : "; - writeValue( childValue ); - if ( ++it == members.end() ) - { - writeCommentAfterValueOnSameLine( childValue ); - break; - } - document_ += ","; - writeCommentAfterValueOnSameLine( childValue ); - } - unindent(); - writeWithIndent( "}" ); - } - } - break; - } -} - - -void -StyledWriter::writeArrayValue( const Value &value ) -{ - unsigned size = value.size(); - if ( size == 0 ) - pushValue( "[]" ); - else - { - bool isArrayMultiLine = isMultineArray( value ); - if ( isArrayMultiLine ) - { - writeWithIndent( "[" ); - indent(); - bool hasChildValue = !childValues_.empty(); - unsigned index =0; - for (;;) - { - const Value &childValue = value[index]; - writeCommentBeforeValue( childValue ); - if ( hasChildValue ) - writeWithIndent( childValues_[index] ); - else - { - writeIndent(); - writeValue( childValue ); - } - if ( ++index == size ) - { - writeCommentAfterValueOnSameLine( childValue ); - break; - } - document_ += ","; - writeCommentAfterValueOnSameLine( childValue ); - } - unindent(); - writeWithIndent( "]" ); - } - else // output on a single line - { - assert( childValues_.size() == size ); - document_ += "[ "; - for ( unsigned index =0; index < size; ++index ) - { - if ( index > 0 ) - document_ += ", "; - document_ += childValues_[index]; - } - document_ += " ]"; - } - } -} - - -bool -StyledWriter::isMultineArray( const Value &value ) -{ - int size = value.size(); - bool isMultiLine = size*3 >= rightMargin_ ; - childValues_.clear(); - for ( int index =0; index < size && !isMultiLine; ++index ) - { - const Value &childValue = value[index]; - isMultiLine = isMultiLine || - ( (childValue.isArray() || childValue.isObject()) && - childValue.size() > 0 ); - } - if ( !isMultiLine ) // check if line length > max line length - { - childValues_.reserve( size ); - addChildValues_ = true; - int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' - for ( int index =0; index < size && !isMultiLine; ++index ) - { - writeValue( value[index] ); - lineLength += int( childValues_[index].length() ); - isMultiLine = isMultiLine && hasCommentForValue( value[index] ); - } - addChildValues_ = false; - isMultiLine = isMultiLine || lineLength >= rightMargin_; - } - return isMultiLine; -} - - -void -StyledWriter::pushValue( const std::string &value ) -{ - if ( addChildValues_ ) - childValues_.push_back( value ); - else - document_ += value; -} - - -void -StyledWriter::writeIndent() -{ - if ( !document_.empty() ) - { - char last = document_[document_.length()-1]; - if ( last == ' ' ) // already indented - return; - if ( last != '\n' ) // Comments may add new-line - document_ += '\n'; - } - document_ += indentString_; -} - - -void -StyledWriter::writeWithIndent( const std::string &value ) -{ - writeIndent(); - document_ += value; -} - - -void -StyledWriter::indent() -{ - indentString_ += std::string( indentSize_, ' ' ); -} - - -void -StyledWriter::unindent() -{ - assert( int(indentString_.size()) >= indentSize_ ); - indentString_.resize( indentString_.size() - indentSize_ ); -} - - -void -StyledWriter::writeCommentBeforeValue( const Value &root ) -{ - if ( !root.hasComment( commentBefore ) ) - return; - document_ += normalizeEOL( root.getComment( commentBefore ) ); - document_ += "\n"; -} - - -void -StyledWriter::writeCommentAfterValueOnSameLine( const Value &root ) -{ - if ( root.hasComment( commentAfterOnSameLine ) ) - document_ += " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); - - if ( root.hasComment( commentAfter ) ) - { - document_ += "\n"; - document_ += normalizeEOL( root.getComment( commentAfter ) ); - document_ += "\n"; - } -} - - -bool -StyledWriter::hasCommentForValue( const Value &value ) -{ - return value.hasComment( commentBefore ) - || value.hasComment( commentAfterOnSameLine ) - || value.hasComment( commentAfter ); -} - - -std::string -StyledWriter::normalizeEOL( const std::string &text ) -{ - std::string normalized; - normalized.reserve( text.length() ); - const char *begin = text.c_str(); - const char *end = begin + text.length(); - const char *current = begin; - while ( current != end ) - { - char c = *current++; - if ( c == '\r' ) // mac or dos EOL - { - if ( *current == '\n' ) // convert dos EOL - ++current; - normalized += '\n'; - } - else // handle unix EOL & other char - normalized += c; - } - return normalized; -} - - -// Class StyledStreamWriter -// ////////////////////////////////////////////////////////////////// - -StyledStreamWriter::StyledStreamWriter( std::string indentation ) - : document_(NULL) - , rightMargin_( 74 ) - , indentation_( indentation ) -{ -} - - -void -StyledStreamWriter::write( std::ostream &out, const Value &root ) -{ - document_ = &out; - addChildValues_ = false; - indentString_ = ""; - writeCommentBeforeValue( root ); - writeValue( root ); - writeCommentAfterValueOnSameLine( root ); - *document_ << "\n"; - document_ = NULL; // Forget the stream, for safety. -} - - -void -StyledStreamWriter::writeValue( const Value &value ) -{ - switch ( value.type() ) - { - case nullValue: - pushValue( "null" ); - break; - case intValue: - pushValue( valueToString( value.asLargestInt() ) ); - break; - case uintValue: - pushValue( valueToString( value.asLargestUInt() ) ); - break; - case realValue: - pushValue( valueToString( value.asDouble() ) ); - break; - case stringValue: - pushValue( valueToQuotedString( value.asCString() ) ); - break; - case booleanValue: - pushValue( valueToString( value.asBool() ) ); - break; - case arrayValue: - writeArrayValue( value); - break; - case objectValue: - { - Value::Members members( value.getMemberNames() ); - if ( members.empty() ) - pushValue( "{}" ); - else - { - writeWithIndent( "{" ); - indent(); - Value::Members::iterator it = members.begin(); - for (;;) - { - const std::string &name = *it; - const Value &childValue = value[name]; - writeCommentBeforeValue( childValue ); - writeWithIndent( valueToQuotedString( name.c_str() ) ); - *document_ << " : "; - writeValue( childValue ); - if ( ++it == members.end() ) - { - writeCommentAfterValueOnSameLine( childValue ); - break; - } - *document_ << ","; - writeCommentAfterValueOnSameLine( childValue ); - } - unindent(); - writeWithIndent( "}" ); - } - } - break; - } -} - - -void -StyledStreamWriter::writeArrayValue( const Value &value ) -{ - unsigned size = value.size(); - if ( size == 0 ) - pushValue( "[]" ); - else - { - bool isArrayMultiLine = isMultineArray( value ); - if ( isArrayMultiLine ) - { - writeWithIndent( "[" ); - indent(); - bool hasChildValue = !childValues_.empty(); - unsigned index =0; - for (;;) - { - const Value &childValue = value[index]; - writeCommentBeforeValue( childValue ); - if ( hasChildValue ) - writeWithIndent( childValues_[index] ); - else - { - writeIndent(); - writeValue( childValue ); - } - if ( ++index == size ) - { - writeCommentAfterValueOnSameLine( childValue ); - break; - } - *document_ << ","; - writeCommentAfterValueOnSameLine( childValue ); - } - unindent(); - writeWithIndent( "]" ); - } - else // output on a single line - { - assert( childValues_.size() == size ); - *document_ << "[ "; - for ( unsigned index =0; index < size; ++index ) - { - if ( index > 0 ) - *document_ << ", "; - *document_ << childValues_[index]; - } - *document_ << " ]"; - } - } -} - - -bool -StyledStreamWriter::isMultineArray( const Value &value ) -{ - int size = value.size(); - bool isMultiLine = size*3 >= rightMargin_ ; - childValues_.clear(); - for ( int index =0; index < size && !isMultiLine; ++index ) - { - const Value &childValue = value[index]; - isMultiLine = isMultiLine || - ( (childValue.isArray() || childValue.isObject()) && - childValue.size() > 0 ); - } - if ( !isMultiLine ) // check if line length > max line length - { - childValues_.reserve( size ); - addChildValues_ = true; - int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' - for ( int index =0; index < size && !isMultiLine; ++index ) - { - writeValue( value[index] ); - lineLength += int( childValues_[index].length() ); - isMultiLine = isMultiLine && hasCommentForValue( value[index] ); - } - addChildValues_ = false; - isMultiLine = isMultiLine || lineLength >= rightMargin_; - } - return isMultiLine; -} - - -void -StyledStreamWriter::pushValue( const std::string &value ) -{ - if ( addChildValues_ ) - childValues_.push_back( value ); - else - *document_ << value; -} - - -void -StyledStreamWriter::writeIndent() -{ - /* - Some comments in this method would have been nice. ;-) - - if ( !document_.empty() ) - { - char last = document_[document_.length()-1]; - if ( last == ' ' ) // already indented - return; - if ( last != '\n' ) // Comments may add new-line - *document_ << '\n'; - } - */ - *document_ << '\n' << indentString_; -} - - -void -StyledStreamWriter::writeWithIndent( const std::string &value ) -{ - writeIndent(); - *document_ << value; -} - - -void -StyledStreamWriter::indent() -{ - indentString_ += indentation_; -} - - -void -StyledStreamWriter::unindent() -{ - assert( indentString_.size() >= indentation_.size() ); - indentString_.resize( indentString_.size() - indentation_.size() ); -} - - -void -StyledStreamWriter::writeCommentBeforeValue( const Value &root ) -{ - if ( !root.hasComment( commentBefore ) ) - return; - *document_ << normalizeEOL( root.getComment( commentBefore ) ); - *document_ << "\n"; -} - - -void -StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root ) -{ - if ( root.hasComment( commentAfterOnSameLine ) ) - *document_ << " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); - - if ( root.hasComment( commentAfter ) ) - { - *document_ << "\n"; - *document_ << normalizeEOL( root.getComment( commentAfter ) ); - *document_ << "\n"; - } -} - - -bool -StyledStreamWriter::hasCommentForValue( const Value &value ) -{ - return value.hasComment( commentBefore ) - || value.hasComment( commentAfterOnSameLine ) - || value.hasComment( commentAfter ); -} - - -std::string -StyledStreamWriter::normalizeEOL( const std::string &text ) -{ - std::string normalized; - normalized.reserve( text.length() ); - const char *begin = text.c_str(); - const char *end = begin + text.length(); - const char *current = begin; - while ( current != end ) - { - char c = *current++; - if ( c == '\r' ) // mac or dos EOL - { - if ( *current == '\n' ) // convert dos EOL - ++current; - normalized += '\n'; - } - else // handle unix EOL & other char - normalized += c; - } - return normalized; -} - - -std::ostream& operator<<( std::ostream &sout, const Value &root ) -{ - Json::StyledStreamWriter writer; - writer.write(sout, root); - return sout; -} - - -} // namespace Json diff --git a/dependencies/build/jsoncpp/sconscript b/dependencies/build/jsoncpp/sconscript deleted file mode 100644 index f6520d18..00000000 --- a/dependencies/build/jsoncpp/sconscript +++ /dev/null @@ -1,8 +0,0 @@ -Import( 'env buildLibrary' ) - -buildLibrary( env, Split( """ - json_reader.cpp - json_value.cpp - json_writer.cpp - """ ), - 'json' ) diff --git a/dependencies/include/json/autolink.h b/dependencies/include/json/autolink.h deleted file mode 100644 index 02328d1f..00000000 --- a/dependencies/include/json/autolink.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSON_AUTOLINK_H_INCLUDED -# define JSON_AUTOLINK_H_INCLUDED - -# include "config.h" - -# ifdef JSON_IN_CPPTL -# include -# endif - -# if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL) -# define CPPTL_AUTOLINK_NAME "json" -# undef CPPTL_AUTOLINK_DLL -# ifdef JSON_DLL -# define CPPTL_AUTOLINK_DLL -# endif -# include "autolink.h" -# endif - -#endif // JSON_AUTOLINK_H_INCLUDED diff --git a/dependencies/include/json/config.h b/dependencies/include/json/config.h deleted file mode 100644 index 7609d45e..00000000 --- a/dependencies/include/json/config.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSON_CONFIG_H_INCLUDED -# define JSON_CONFIG_H_INCLUDED - -/// If defined, indicates that json library is embedded in CppTL library. -//# define JSON_IN_CPPTL 1 - -/// If defined, indicates that json may leverage CppTL library -//# define JSON_USE_CPPTL 1 -/// If defined, indicates that cpptl vector based map should be used instead of std::map -/// as Value container. -//# define JSON_USE_CPPTL_SMALLMAP 1 -/// If defined, indicates that Json specific container should be used -/// (hash table & simple deque container with customizable allocator). -/// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332 -//# define JSON_VALUE_USE_INTERNAL_MAP 1 -/// Force usage of standard new/malloc based allocator instead of memory pool based allocator. -/// The memory pools allocator used optimization (initializing Value and ValueInternalLink -/// as if it was a POD) that may cause some validation tool to report errors. -/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined. -//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1 - -/// If defined, indicates that Json use exception to report invalid type manipulation -/// instead of C assert macro. -# define JSON_USE_EXCEPTION 1 - -/// If defined, indicates that the source file is amalgated -/// to prevent private header inclusion. -/// Remarks: it is automatically defined in the generated amalgated header. -// #define JSON_IS_AMALGAMATION - - -# ifdef JSON_IN_CPPTL -# include -# ifndef JSON_USE_CPPTL -# define JSON_USE_CPPTL 1 -# endif -# endif - -# ifdef JSON_IN_CPPTL -# define JSON_API CPPTL_API -# elif defined(JSON_DLL_BUILD) -# define JSON_API __declspec(dllexport) -# elif defined(JSON_DLL) -# define JSON_API __declspec(dllimport) -# else -# define JSON_API -# endif - -// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer -// Storages, and 64 bits integer support is disabled. -// #define JSON_NO_INT64 1 - -#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6 -// Microsoft Visual Studio 6 only support conversion from __int64 to double -// (no conversion from unsigned __int64). -#define JSON_USE_INT64_DOUBLE_CONVERSION 1 -#endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6 - -#if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008 -/// Indicates that the following function is deprecated. -# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) -#endif - -#if !defined(JSONCPP_DEPRECATED) -# define JSONCPP_DEPRECATED(message) -#endif // if !defined(JSONCPP_DEPRECATED) - -namespace Json { - typedef int Int; - typedef unsigned int UInt; -# if defined(JSON_NO_INT64) - typedef int LargestInt; - typedef unsigned int LargestUInt; -# undef JSON_HAS_INT64 -# else // if defined(JSON_NO_INT64) - // For Microsoft Visual use specific types as long long is not supported -# if defined(_MSC_VER) // Microsoft Visual Studio - typedef __int64 Int64; - typedef unsigned __int64 UInt64; -# else // if defined(_MSC_VER) // Other platforms, use long long - typedef long long int Int64; - typedef unsigned long long int UInt64; -# endif // if defined(_MSC_VER) - typedef Int64 LargestInt; - typedef UInt64 LargestUInt; -# define JSON_HAS_INT64 -# endif // if defined(JSON_NO_INT64) -} // end namespace Json - - -#endif // JSON_CONFIG_H_INCLUDED diff --git a/dependencies/include/json/features.h b/dependencies/include/json/features.h deleted file mode 100644 index 43532784..00000000 --- a/dependencies/include/json/features.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef CPPTL_JSON_FEATURES_H_INCLUDED -# define CPPTL_JSON_FEATURES_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "forwards.h" -#endif // if !defined(JSON_IS_AMALGAMATION) - -namespace Json { - - /** \brief Configuration passed to reader and writer. - * This configuration object can be used to force the Reader or Writer - * to behave in a standard conforming way. - */ - class JSON_API Features - { - public: - /** \brief A configuration that allows all features and assumes all strings are UTF-8. - * - C & C++ comments are allowed - * - Root object can be any JSON value - * - Assumes Value strings are encoded in UTF-8 - */ - static Features all(); - - /** \brief A configuration that is strictly compatible with the JSON specification. - * - Comments are forbidden. - * - Root object must be either an array or an object value. - * - Assumes Value strings are encoded in UTF-8 - */ - static Features strictMode(); - - /** \brief Initialize the configuration like JsonConfig::allFeatures; - */ - Features(); - - /// \c true if comments are allowed. Default: \c true. - bool allowComments_; - - /// \c true if root must be either an array or an object value. Default: \c false. - bool strictRoot_; - }; - -} // namespace Json - -#endif // CPPTL_JSON_FEATURES_H_INCLUDED diff --git a/dependencies/include/json/forwards.h b/dependencies/include/json/forwards.h deleted file mode 100644 index ab863da8..00000000 --- a/dependencies/include/json/forwards.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSON_FORWARDS_H_INCLUDED -# define JSON_FORWARDS_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "config.h" -#endif // if !defined(JSON_IS_AMALGAMATION) - -namespace Json { - - // writer.h - class FastWriter; - class StyledWriter; - - // reader.h - class Reader; - - // features.h - class Features; - - // value.h - typedef unsigned int ArrayIndex; - class StaticString; - class Path; - class PathArgument; - class Value; - class ValueIteratorBase; - class ValueIterator; - class ValueConstIterator; -#ifdef JSON_VALUE_USE_INTERNAL_MAP - class ValueMapAllocator; - class ValueInternalLink; - class ValueInternalArray; - class ValueInternalMap; -#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP - -} // namespace Json - - -#endif // JSON_FORWARDS_H_INCLUDED diff --git a/dependencies/include/json/json.h b/dependencies/include/json/json.h deleted file mode 100644 index da5fc967..00000000 --- a/dependencies/include/json/json.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSON_JSON_H_INCLUDED -# define JSON_JSON_H_INCLUDED - -# include "autolink.h" -# include "value.h" -# include "reader.h" -# include "writer.h" -# include "features.h" - -#endif // JSON_JSON_H_INCLUDED diff --git a/dependencies/include/json/reader.h b/dependencies/include/json/reader.h deleted file mode 100644 index 0a324dfc..00000000 --- a/dependencies/include/json/reader.h +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef CPPTL_JSON_READER_H_INCLUDED -# define CPPTL_JSON_READER_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "features.h" -# include "value.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -# include -# include -# include -# include - -namespace Json { - - /** \brief Unserialize a JSON document into a Value. - * - */ - class JSON_API Reader - { - public: - typedef char Char; - typedef const Char *Location; - - /** \brief Constructs a Reader allowing all features - * for parsing. - */ - Reader(); - - /** \brief Constructs a Reader allowing the specified feature set - * for parsing. - */ - Reader( const Features &features ); - - /** \brief Read a Value from a JSON document. - * \param document UTF-8 encoded string containing the document to read. - * \param root [out] Contains the root value of the document if it was - * successfully parsed. - * \param collectComments \c true to collect comment and allow writing them back during - * serialization, \c false to discard comments. - * This parameter is ignored if Features::allowComments_ - * is \c false. - * \return \c true if the document was successfully parsed, \c false if an error occurred. - */ - bool parse( const std::string &document, - Value &root, - bool collectComments = true ); - - /** \brief Read a Value from a JSON document. - * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the document to read. - * \param endDoc Pointer on the end of the UTF-8 encoded string of the document to read. - \ Must be >= beginDoc. - * \param root [out] Contains the root value of the document if it was - * successfully parsed. - * \param collectComments \c true to collect comment and allow writing them back during - * serialization, \c false to discard comments. - * This parameter is ignored if Features::allowComments_ - * is \c false. - * \return \c true if the document was successfully parsed, \c false if an error occurred. - */ - bool parse( const char *beginDoc, const char *endDoc, - Value &root, - bool collectComments = true ); - - /// \brief Parse from input stream. - /// \see Json::operator>>(std::istream&, Json::Value&). - bool parse( std::istream &is, - Value &root, - bool collectComments = true ); - - /** \brief Returns a user friendly string that list errors in the parsed document. - * \return Formatted error message with the list of errors with their location in - * the parsed document. An empty string is returned if no error occurred - * during parsing. - * \deprecated Use getFormattedErrorMessages() instead (typo fix). - */ - JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead") - std::string getFormatedErrorMessages() const; - - /** \brief Returns a user friendly string that list errors in the parsed document. - * \return Formatted error message with the list of errors with their location in - * the parsed document. An empty string is returned if no error occurred - * during parsing. - */ - std::string getFormattedErrorMessages() const; - - private: - enum TokenType - { - tokenEndOfStream = 0, - tokenObjectBegin, - tokenObjectEnd, - tokenArrayBegin, - tokenArrayEnd, - tokenString, - tokenNumber, - tokenTrue, - tokenFalse, - tokenNull, - tokenArraySeparator, - tokenMemberSeparator, - tokenComment, - tokenError - }; - - class Token - { - public: - TokenType type_; - Location start_; - Location end_; - }; - - class ErrorInfo - { - public: - Token token_; - std::string message_; - Location extra_; - }; - - typedef std::deque Errors; - - bool expectToken( TokenType type, Token &token, const char *message ); - bool readToken( Token &token ); - void skipSpaces(); - bool match( Location pattern, - int patternLength ); - bool readComment(); - bool readCStyleComment(); - bool readCppStyleComment(); - bool readString(); - void readNumber(); - bool readValue(); - bool readObject( Token &token ); - bool readArray( Token &token ); - bool decodeNumber( Token &token ); - bool decodeString( Token &token ); - bool decodeString( Token &token, std::string &decoded ); - bool decodeDouble( Token &token ); - bool decodeUnicodeCodePoint( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ); - bool decodeUnicodeEscapeSequence( Token &token, - Location ¤t, - Location end, - unsigned int &unicode ); - bool addError( const std::string &message, - Token &token, - Location extra = 0 ); - bool recoverFromError( TokenType skipUntilToken ); - bool addErrorAndRecover( const std::string &message, - Token &token, - TokenType skipUntilToken ); - void skipUntilSpace(); - Value ¤tValue(); - Char getNextChar(); - void getLocationLineAndColumn( Location location, - int &line, - int &column ) const; - std::string getLocationLineAndColumn( Location location ) const; - void addComment( Location begin, - Location end, - CommentPlacement placement ); - void skipCommentTokens( Token &token ); - - typedef std::stack Nodes; - Nodes nodes_; - Errors errors_; - std::string document_; - Location begin_; - Location end_; - Location current_; - Location lastValueEnd_; - Value *lastValue_; - std::string commentsBefore_; - Features features_; - bool collectComments_; - }; - - /** \brief Read from 'sin' into 'root'. - - Always keep comments from the input JSON. - - This can be used to read a file into a particular sub-object. - For example: - \code - Json::Value root; - cin >> root["dir"]["file"]; - cout << root; - \endcode - Result: - \verbatim - { - "dir": { - "file": { - // The input stream JSON would be nested here. - } - } - } - \endverbatim - \throw std::exception on parse error. - \see Json::operator<<() - */ - std::istream& operator>>( std::istream&, Value& ); - -} // namespace Json - -#endif // CPPTL_JSON_READER_H_INCLUDED diff --git a/dependencies/include/json/value.h b/dependencies/include/json/value.h deleted file mode 100644 index 32e3455e..00000000 --- a/dependencies/include/json/value.h +++ /dev/null @@ -1,1103 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef CPPTL_JSON_H_INCLUDED -# define CPPTL_JSON_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "forwards.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -# include -# include - -# ifndef JSON_USE_CPPTL_SMALLMAP -# include -# else -# include -# endif -# ifdef JSON_USE_CPPTL -# include -# endif - -/** \brief JSON (JavaScript Object Notation). - */ -namespace Json { - - /** \brief Type of the value held by a Value object. - */ - enum ValueType - { - nullValue = 0, ///< 'null' value - intValue, ///< signed integer value - uintValue, ///< unsigned integer value - realValue, ///< double value - stringValue, ///< UTF-8 string value - booleanValue, ///< bool value - arrayValue, ///< array value (ordered list) - objectValue ///< object value (collection of name/value pairs). - }; - - enum CommentPlacement - { - commentBefore = 0, ///< a comment placed on the line before a value - commentAfterOnSameLine, ///< a comment just after a value on the same line - commentAfter, ///< a comment on the line after a value (only make sense for root value) - numberOfCommentPlacement - }; - -//# ifdef JSON_USE_CPPTL -// typedef CppTL::AnyEnumerator EnumMemberNames; -// typedef CppTL::AnyEnumerator EnumValues; -//# endif - - /** \brief Lightweight wrapper to tag static string. - * - * Value constructor and objectValue member assignement takes advantage of the - * StaticString and avoid the cost of string duplication when storing the - * string or the member name. - * - * Example of usage: - * \code - * Json::Value aValue( StaticString("some text") ); - * Json::Value object; - * static const StaticString code("code"); - * object[code] = 1234; - * \endcode - */ - class JSON_API StaticString - { - public: - explicit StaticString( const char *czstring ) - : str_( czstring ) - { - } - - operator const char *() const - { - return str_; - } - - const char *c_str() const - { - return str_; - } - - private: - const char *str_; - }; - - /** \brief Represents a JSON value. - * - * This class is a discriminated union wrapper that can represents a: - * - signed integer [range: Value::minInt - Value::maxInt] - * - unsigned integer (range: 0 - Value::maxUInt) - * - double - * - UTF-8 string - * - boolean - * - 'null' - * - an ordered list of Value - * - collection of name/value pairs (javascript object) - * - * The type of the held value is represented by a #ValueType and - * can be obtained using type(). - * - * values of an #objectValue or #arrayValue can be accessed using operator[]() methods. - * Non const methods will automatically create the a #nullValue element - * if it does not exist. - * The sequence of an #arrayValue will be automatically resize and initialized - * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. - * - * The get() methods can be used to obtanis default value in the case the required element - * does not exist. - * - * It is possible to iterate over the list of a #objectValue values using - * the getMemberNames() method. - */ - class JSON_API Value - { - friend class ValueIteratorBase; -# ifdef JSON_VALUE_USE_INTERNAL_MAP - friend class ValueInternalLink; - friend class ValueInternalMap; -# endif - public: - typedef std::vector Members; - typedef ValueIterator iterator; - typedef ValueConstIterator const_iterator; - typedef Json::UInt UInt; - typedef Json::Int Int; -# if defined(JSON_HAS_INT64) - typedef Json::UInt64 UInt64; - typedef Json::Int64 Int64; -#endif // defined(JSON_HAS_INT64) - typedef Json::LargestInt LargestInt; - typedef Json::LargestUInt LargestUInt; - typedef Json::ArrayIndex ArrayIndex; - - static const Value null; - /// Minimum signed integer value that can be stored in a Json::Value. - static const LargestInt minLargestInt; - /// Maximum signed integer value that can be stored in a Json::Value. - static const LargestInt maxLargestInt; - /// Maximum unsigned integer value that can be stored in a Json::Value. - static const LargestUInt maxLargestUInt; - - /// Minimum signed int value that can be stored in a Json::Value. - static const Int minInt; - /// Maximum signed int value that can be stored in a Json::Value. - static const Int maxInt; - /// Maximum unsigned int value that can be stored in a Json::Value. - static const UInt maxUInt; - - /// Minimum signed 64 bits int value that can be stored in a Json::Value. - static const Int64 minInt64; - /// Maximum signed 64 bits int value that can be stored in a Json::Value. - static const Int64 maxInt64; - /// Maximum unsigned 64 bits int value that can be stored in a Json::Value. - static const UInt64 maxUInt64; - - private: -#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION -# ifndef JSON_VALUE_USE_INTERNAL_MAP - class CZString - { - public: - enum DuplicationPolicy - { - noDuplication = 0, - duplicate, - duplicateOnCopy - }; - CZString( ArrayIndex index ); - CZString( const char *cstr, DuplicationPolicy allocate ); - CZString( const CZString &other ); - ~CZString(); - CZString &operator =( const CZString &other ); - bool operator<( const CZString &other ) const; - bool operator==( const CZString &other ) const; - ArrayIndex index() const; - const char *c_str() const; - bool isStaticString() const; - private: - void swap( CZString &other ); - const char *cstr_; - ArrayIndex index_; - }; - - public: -# ifndef JSON_USE_CPPTL_SMALLMAP - typedef std::map ObjectValues; -# else - typedef CppTL::SmallMap ObjectValues; -# endif // ifndef JSON_USE_CPPTL_SMALLMAP -# endif // ifndef JSON_VALUE_USE_INTERNAL_MAP -#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - public: - /** \brief Create a default Value of the given type. - - This is a very useful constructor. - To create an empty array, pass arrayValue. - To create an empty object, pass objectValue. - Another Value can then be set to this one by assignment. - This is useful since clear() and resize() will not alter types. - - Examples: - \code - Json::Value null_value; // null - Json::Value arr_value(Json::arrayValue); // [] - Json::Value obj_value(Json::objectValue); // {} - \endcode - */ - Value( ValueType type = nullValue ); - Value( Int value ); - Value( UInt value ); -#if defined(JSON_HAS_INT64) - Value( Int64 value ); - Value( UInt64 value ); -#endif // if defined(JSON_HAS_INT64) - Value( double value ); - Value( const char *value ); - Value( const char *beginValue, const char *endValue ); - /** \brief Constructs a value from a static string. - - * Like other value string constructor but do not duplicate the string for - * internal storage. The given string must remain alive after the call to this - * constructor. - * Example of usage: - * \code - * Json::Value aValue( StaticString("some text") ); - * \endcode - */ - Value( const StaticString &value ); - Value( const std::string &value ); -# ifdef JSON_USE_CPPTL - Value( const CppTL::ConstString &value ); -# endif - Value( bool value ); - Value( const Value &other ); - ~Value(); - - Value &operator=( const Value &other ); - /// Swap values. - /// \note Currently, comments are intentionally not swapped, for - /// both logic and efficiency. - void swap( Value &other ); - - ValueType type() const; - - bool operator <( const Value &other ) const; - bool operator <=( const Value &other ) const; - bool operator >=( const Value &other ) const; - bool operator >( const Value &other ) const; - - bool operator ==( const Value &other ) const; - bool operator !=( const Value &other ) const; - - int compare( const Value &other ) const; - - const char *asCString() const; - std::string asString() const; -# ifdef JSON_USE_CPPTL - CppTL::ConstString asConstString() const; -# endif - Int asInt() const; - UInt asUInt() const; - Int64 asInt64() const; - UInt64 asUInt64() const; - LargestInt asLargestInt() const; - LargestUInt asLargestUInt() const; - float asFloat() const; - double asDouble() const; - bool asBool() const; - - bool isNull() const; - bool isBool() const; - bool isInt() const; - bool isUInt() const; - bool isIntegral() const; - bool isDouble() const; - bool isNumeric() const; - bool isString() const; - bool isArray() const; - bool isObject() const; - - bool isConvertibleTo( ValueType other ) const; - - /// Number of values in array or object - ArrayIndex size() const; - - /// \brief Return true if empty array, empty object, or null; - /// otherwise, false. - bool empty() const; - - /// Return isNull() - bool operator!() const; - - /// Remove all object members and array elements. - /// \pre type() is arrayValue, objectValue, or nullValue - /// \post type() is unchanged - void clear(); - - /// Resize the array to size elements. - /// New elements are initialized to null. - /// May only be called on nullValue or arrayValue. - /// \pre type() is arrayValue or nullValue - /// \post type() is arrayValue - void resize( ArrayIndex size ); - - /// Access an array element (zero based index ). - /// If the array contains less than index element, then null value are inserted - /// in the array so that its size is index+1. - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - Value &operator[]( ArrayIndex index ); - - /// Access an array element (zero based index ). - /// If the array contains less than index element, then null value are inserted - /// in the array so that its size is index+1. - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - Value &operator[]( int index ); - - /// Access an array element (zero based index ) - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - const Value &operator[]( ArrayIndex index ) const; - - /// Access an array element (zero based index ) - /// (You may need to say 'value[0u]' to get your compiler to distinguish - /// this from the operator[] which takes a string.) - const Value &operator[]( int index ) const; - - /// If the array contains at least index+1 elements, returns the element value, - /// otherwise returns defaultValue. - Value get( ArrayIndex index, - const Value &defaultValue ) const; - /// Return true if index < size(). - bool isValidIndex( ArrayIndex index ) const; - /// \brief Append value to array at the end. - /// - /// Equivalent to jsonvalue[jsonvalue.size()] = value; - Value &append( const Value &value ); - - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const char *key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const char *key ) const; - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const std::string &key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const std::string &key ) const; - /** \brief Access an object value by name, create a null member if it does not exist. - - * If the object as no entry for that name, then the member name used to store - * the new entry is not duplicated. - * Example of use: - * \code - * Json::Value object; - * static const StaticString code("code"); - * object[code] = 1234; - * \endcode - */ - Value &operator[]( const StaticString &key ); -# ifdef JSON_USE_CPPTL - /// Access an object value by name, create a null member if it does not exist. - Value &operator[]( const CppTL::ConstString &key ); - /// Access an object value by name, returns null if there is no member with that name. - const Value &operator[]( const CppTL::ConstString &key ) const; -# endif - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const char *key, - const Value &defaultValue ) const; - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const std::string &key, - const Value &defaultValue ) const; -# ifdef JSON_USE_CPPTL - /// Return the member named key if it exist, defaultValue otherwise. - Value get( const CppTL::ConstString &key, - const Value &defaultValue ) const; -# endif - /// \brief Remove and return the named member. - /// - /// Do nothing if it did not exist. - /// \return the removed Value, or null. - /// \pre type() is objectValue or nullValue - /// \post type() is unchanged - Value removeMember( const char* key ); - /// Same as removeMember(const char*) - Value removeMember( const std::string &key ); - - /// Return true if the object has a member named key. - bool isMember( const char *key ) const; - /// Return true if the object has a member named key. - bool isMember( const std::string &key ) const; -# ifdef JSON_USE_CPPTL - /// Return true if the object has a member named key. - bool isMember( const CppTL::ConstString &key ) const; -# endif - - /// \brief Return a list of the member names. - /// - /// If null, return an empty list. - /// \pre type() is objectValue or nullValue - /// \post if type() was nullValue, it remains nullValue - Members getMemberNames() const; - -//# ifdef JSON_USE_CPPTL -// EnumMemberNames enumMemberNames() const; -// EnumValues enumValues() const; -//# endif - - /// Comments must be //... or /* ... */ - void setComment( const char *comment, - CommentPlacement placement ); - /// Comments must be //... or /* ... */ - void setComment( const std::string &comment, - CommentPlacement placement ); - bool hasComment( CommentPlacement placement ) const; - /// Include delimiters and embedded newlines. - std::string getComment( CommentPlacement placement ) const; - - std::string toStyledString() const; - - const_iterator begin() const; - const_iterator end() const; - - iterator begin(); - iterator end(); - - private: - Value &resolveReference( const char *key, - bool isStatic ); - -# ifdef JSON_VALUE_USE_INTERNAL_MAP - inline bool isItemAvailable() const - { - return itemIsUsed_ == 0; - } - - inline void setItemUsed( bool isUsed = true ) - { - itemIsUsed_ = isUsed ? 1 : 0; - } - - inline bool isMemberNameStatic() const - { - return memberNameIsStatic_ == 0; - } - - inline void setMemberNameIsStatic( bool isStatic ) - { - memberNameIsStatic_ = isStatic ? 1 : 0; - } -# endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP - - private: - struct CommentInfo - { - CommentInfo(); - ~CommentInfo(); - - void setComment( const char *text ); - - char *comment_; - }; - - //struct MemberNamesTransform - //{ - // typedef const char *result_type; - // const char *operator()( const CZString &name ) const - // { - // return name.c_str(); - // } - //}; - - union ValueHolder - { - LargestInt int_; - LargestUInt uint_; - double real_; - bool bool_; - char *string_; -# ifdef JSON_VALUE_USE_INTERNAL_MAP - ValueInternalArray *array_; - ValueInternalMap *map_; -#else - ObjectValues *map_; -# endif - } value_; - ValueType type_ : 8; - int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. -# ifdef JSON_VALUE_USE_INTERNAL_MAP - unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container. - int memberNameIsStatic_ : 1; // used by the ValueInternalMap container. -# endif - CommentInfo *comments_; - }; - - - /** \brief Experimental and untested: represents an element of the "path" to access a node. - */ - class PathArgument - { - public: - friend class Path; - - PathArgument(); - PathArgument( ArrayIndex index ); - PathArgument( const char *key ); - PathArgument( const std::string &key ); - - private: - enum Kind - { - kindNone = 0, - kindIndex, - kindKey - }; - std::string key_; - ArrayIndex index_; - Kind kind_; - }; - - /** \brief Experimental and untested: represents a "path" to access a node. - * - * Syntax: - * - "." => root node - * - ".[n]" => elements at index 'n' of root node (an array value) - * - ".name" => member named 'name' of root node (an object value) - * - ".name1.name2.name3" - * - ".[0][1][2].name1[3]" - * - ".%" => member name is provided as parameter - * - ".[%]" => index is provied as parameter - */ - class Path - { - public: - Path( const std::string &path, - const PathArgument &a1 = PathArgument(), - const PathArgument &a2 = PathArgument(), - const PathArgument &a3 = PathArgument(), - const PathArgument &a4 = PathArgument(), - const PathArgument &a5 = PathArgument() ); - - const Value &resolve( const Value &root ) const; - Value resolve( const Value &root, - const Value &defaultValue ) const; - /// Creates the "path" to access the specified node and returns a reference on the node. - Value &make( Value &root ) const; - - private: - typedef std::vector InArgs; - typedef std::vector Args; - - void makePath( const std::string &path, - const InArgs &in ); - void addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, - PathArgument::Kind kind ); - void invalidPath( const std::string &path, - int location ); - - Args args_; - }; - - - -#ifdef JSON_VALUE_USE_INTERNAL_MAP - /** \brief Allocator to customize Value internal map. - * Below is an example of a simple implementation (default implementation actually - * use memory pool for speed). - * \code - class DefaultValueMapAllocator : public ValueMapAllocator - { - public: // overridden from ValueMapAllocator - virtual ValueInternalMap *newMap() - { - return new ValueInternalMap(); - } - - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) - { - return new ValueInternalMap( other ); - } - - virtual void destructMap( ValueInternalMap *map ) - { - delete map; - } - - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) - { - return new ValueInternalLink[size]; - } - - virtual void releaseMapBuckets( ValueInternalLink *links ) - { - delete [] links; - } - - virtual ValueInternalLink *allocateMapLink() - { - return new ValueInternalLink(); - } - - virtual void releaseMapLink( ValueInternalLink *link ) - { - delete link; - } - }; - * \endcode - */ - class JSON_API ValueMapAllocator - { - public: - virtual ~ValueMapAllocator(); - virtual ValueInternalMap *newMap() = 0; - virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0; - virtual void destructMap( ValueInternalMap *map ) = 0; - virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0; - virtual void releaseMapBuckets( ValueInternalLink *links ) = 0; - virtual ValueInternalLink *allocateMapLink() = 0; - virtual void releaseMapLink( ValueInternalLink *link ) = 0; - }; - - /** \brief ValueInternalMap hash-map bucket chain link (for internal use only). - * \internal previous_ & next_ allows for bidirectional traversal. - */ - class JSON_API ValueInternalLink - { - public: - enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture. - enum InternalFlags { - flagAvailable = 0, - flagUsed = 1 - }; - - ValueInternalLink(); - - ~ValueInternalLink(); - - Value items_[itemPerLink]; - char *keys_[itemPerLink]; - ValueInternalLink *previous_; - ValueInternalLink *next_; - }; - - - /** \brief A linked page based hash-table implementation used internally by Value. - * \internal ValueInternalMap is a tradional bucket based hash-table, with a linked - * list in each bucket to handle collision. There is an addional twist in that - * each node of the collision linked list is a page containing a fixed amount of - * value. This provides a better compromise between memory usage and speed. - * - * Each bucket is made up of a chained list of ValueInternalLink. The last - * link of a given bucket can be found in the 'previous_' field of the following bucket. - * The last link of the last bucket is stored in tailLink_ as it has no following bucket. - * Only the last link of a bucket may contains 'available' item. The last link always - * contains at least one element unless is it the bucket one very first link. - */ - class JSON_API ValueInternalMap - { - friend class ValueIteratorBase; - friend class Value; - public: - typedef unsigned int HashKey; - typedef unsigned int BucketIndex; - -# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - struct IteratorState - { - IteratorState() - : map_(0) - , link_(0) - , itemIndex_(0) - , bucketIndex_(0) - { - } - ValueInternalMap *map_; - ValueInternalLink *link_; - BucketIndex itemIndex_; - BucketIndex bucketIndex_; - }; -# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - ValueInternalMap(); - ValueInternalMap( const ValueInternalMap &other ); - ValueInternalMap &operator =( const ValueInternalMap &other ); - ~ValueInternalMap(); - - void swap( ValueInternalMap &other ); - - BucketIndex size() const; - - void clear(); - - bool reserveDelta( BucketIndex growth ); - - bool reserve( BucketIndex newItemCount ); - - const Value *find( const char *key ) const; - - Value *find( const char *key ); - - Value &resolveReference( const char *key, - bool isStatic ); - - void remove( const char *key ); - - void doActualRemove( ValueInternalLink *link, - BucketIndex index, - BucketIndex bucketIndex ); - - ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex ); - - Value &setNewItem( const char *key, - bool isStatic, - ValueInternalLink *link, - BucketIndex index ); - - Value &unsafeAdd( const char *key, - bool isStatic, - HashKey hashedKey ); - - HashKey hash( const char *key ) const; - - int compare( const ValueInternalMap &other ) const; - - private: - void makeBeginIterator( IteratorState &it ) const; - void makeEndIterator( IteratorState &it ) const; - static bool equals( const IteratorState &x, const IteratorState &other ); - static void increment( IteratorState &iterator ); - static void incrementBucket( IteratorState &iterator ); - static void decrement( IteratorState &iterator ); - static const char *key( const IteratorState &iterator ); - static const char *key( const IteratorState &iterator, bool &isStatic ); - static Value &value( const IteratorState &iterator ); - static int distance( const IteratorState &x, const IteratorState &y ); - - private: - ValueInternalLink *buckets_; - ValueInternalLink *tailLink_; - BucketIndex bucketsSize_; - BucketIndex itemCount_; - }; - - /** \brief A simplified deque implementation used internally by Value. - * \internal - * It is based on a list of fixed "page", each page contains a fixed number of items. - * Instead of using a linked-list, a array of pointer is used for fast item look-up. - * Look-up for an element is as follow: - * - compute page index: pageIndex = itemIndex / itemsPerPage - * - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage] - * - * Insertion is amortized constant time (only the array containing the index of pointers - * need to be reallocated when items are appended). - */ - class JSON_API ValueInternalArray - { - friend class Value; - friend class ValueIteratorBase; - public: - enum { itemsPerPage = 8 }; // should be a power of 2 for fast divide and modulo. - typedef Value::ArrayIndex ArrayIndex; - typedef unsigned int PageIndex; - -# ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - struct IteratorState // Must be a POD - { - IteratorState() - : array_(0) - , currentPageIndex_(0) - , currentItemIndex_(0) - { - } - ValueInternalArray *array_; - Value **currentPageIndex_; - unsigned int currentItemIndex_; - }; -# endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION - - ValueInternalArray(); - ValueInternalArray( const ValueInternalArray &other ); - ValueInternalArray &operator =( const ValueInternalArray &other ); - ~ValueInternalArray(); - void swap( ValueInternalArray &other ); - - void clear(); - void resize( ArrayIndex newSize ); - - Value &resolveReference( ArrayIndex index ); - - Value *find( ArrayIndex index ) const; - - ArrayIndex size() const; - - int compare( const ValueInternalArray &other ) const; - - private: - static bool equals( const IteratorState &x, const IteratorState &other ); - static void increment( IteratorState &iterator ); - static void decrement( IteratorState &iterator ); - static Value &dereference( const IteratorState &iterator ); - static Value &unsafeDereference( const IteratorState &iterator ); - static int distance( const IteratorState &x, const IteratorState &y ); - static ArrayIndex indexOf( const IteratorState &iterator ); - void makeBeginIterator( IteratorState &it ) const; - void makeEndIterator( IteratorState &it ) const; - void makeIterator( IteratorState &it, ArrayIndex index ) const; - - void makeIndexValid( ArrayIndex index ); - - Value **pages_; - ArrayIndex size_; - PageIndex pageCount_; - }; - - /** \brief Experimental: do not use. Allocator to customize Value internal array. - * Below is an example of a simple implementation (actual implementation use - * memory pool). - \code -class DefaultValueArrayAllocator : public ValueArrayAllocator -{ -public: // overridden from ValueArrayAllocator - virtual ~DefaultValueArrayAllocator() - { - } - - virtual ValueInternalArray *newArray() - { - return new ValueInternalArray(); - } - - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) - { - return new ValueInternalArray( other ); - } - - virtual void destruct( ValueInternalArray *array ) - { - delete array; - } - - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) - { - ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1; - if ( minNewIndexCount > newIndexCount ) - newIndexCount = minNewIndexCount; - void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount ); - if ( !newIndexes ) - throw std::bad_alloc(); - indexCount = newIndexCount; - indexes = static_cast( newIndexes ); - } - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) - { - if ( indexes ) - free( indexes ); - } - - virtual Value *allocateArrayPage() - { - return static_cast( malloc( sizeof(Value) * ValueInternalArray::itemsPerPage ) ); - } - - virtual void releaseArrayPage( Value *value ) - { - if ( value ) - free( value ); - } -}; - \endcode - */ - class JSON_API ValueArrayAllocator - { - public: - virtual ~ValueArrayAllocator(); - virtual ValueInternalArray *newArray() = 0; - virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0; - virtual void destructArray( ValueInternalArray *array ) = 0; - /** \brief Reallocate array page index. - * Reallocates an array of pointer on each page. - * \param indexes [input] pointer on the current index. May be \c NULL. - * [output] pointer on the new index of at least - * \a minNewIndexCount pages. - * \param indexCount [input] current number of pages in the index. - * [output] number of page the reallocated index can handle. - * \b MUST be >= \a minNewIndexCount. - * \param minNewIndexCount Minimum number of page the new index must be able to - * handle. - */ - virtual void reallocateArrayPageIndex( Value **&indexes, - ValueInternalArray::PageIndex &indexCount, - ValueInternalArray::PageIndex minNewIndexCount ) = 0; - virtual void releaseArrayPageIndex( Value **indexes, - ValueInternalArray::PageIndex indexCount ) = 0; - virtual Value *allocateArrayPage() = 0; - virtual void releaseArrayPage( Value *value ) = 0; - }; -#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP - - - /** \brief base class for Value iterators. - * - */ - class ValueIteratorBase - { - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef ValueIteratorBase SelfType; - - ValueIteratorBase(); -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t ); -#else - ValueIteratorBase( const ValueInternalArray::IteratorState &state ); - ValueIteratorBase( const ValueInternalMap::IteratorState &state ); -#endif - - bool operator ==( const SelfType &other ) const - { - return isEqual( other ); - } - - bool operator !=( const SelfType &other ) const - { - return !isEqual( other ); - } - - difference_type operator -( const SelfType &other ) const - { - return computeDistance( other ); - } - - /// Return either the index or the member name of the referenced value as a Value. - Value key() const; - - /// Return the index of the referenced Value. -1 if it is not an arrayValue. - UInt index() const; - - /// Return the member name of the referenced Value. "" if it is not an objectValue. - const char *memberName() const; - - protected: - Value &deref() const; - - void increment(); - - void decrement(); - - difference_type computeDistance( const SelfType &other ) const; - - bool isEqual( const SelfType &other ) const; - - void copy( const SelfType &other ); - - private: -#ifndef JSON_VALUE_USE_INTERNAL_MAP - Value::ObjectValues::iterator current_; - // Indicates that iterator is for a null value. - bool isNull_; -#else - union - { - ValueInternalArray::IteratorState array_; - ValueInternalMap::IteratorState map_; - } iterator_; - bool isArray_; -#endif - }; - - /** \brief const iterator for object and array value. - * - */ - class ValueConstIterator : public ValueIteratorBase - { - friend class Value; - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef const Value &reference; - typedef const Value *pointer; - typedef ValueConstIterator SelfType; - - ValueConstIterator(); - private: - /*! \internal Use by Value to create an iterator. - */ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t ); -#else - ValueConstIterator( const ValueInternalArray::IteratorState &state ); - ValueConstIterator( const ValueInternalMap::IteratorState &state ); -#endif - public: - SelfType &operator =( const ValueIteratorBase &other ); - - SelfType operator++( int ) - { - SelfType temp( *this ); - ++*this; - return temp; - } - - SelfType operator--( int ) - { - SelfType temp( *this ); - --*this; - return temp; - } - - SelfType &operator--() - { - decrement(); - return *this; - } - - SelfType &operator++() - { - increment(); - return *this; - } - - reference operator *() const - { - return deref(); - } - }; - - - /** \brief Iterator for object and array value. - */ - class ValueIterator : public ValueIteratorBase - { - friend class Value; - public: - typedef unsigned int size_t; - typedef int difference_type; - typedef Value &reference; - typedef Value *pointer; - typedef ValueIterator SelfType; - - ValueIterator(); - ValueIterator( const ValueConstIterator &other ); - ValueIterator( const ValueIterator &other ); - private: - /*! \internal Use by Value to create an iterator. - */ -#ifndef JSON_VALUE_USE_INTERNAL_MAP - explicit ValueIterator( const Value::ObjectValues::iterator ¤t ); -#else - ValueIterator( const ValueInternalArray::IteratorState &state ); - ValueIterator( const ValueInternalMap::IteratorState &state ); -#endif - public: - - SelfType &operator =( const SelfType &other ); - - SelfType operator++( int ) - { - SelfType temp( *this ); - ++*this; - return temp; - } - - SelfType operator--( int ) - { - SelfType temp( *this ); - --*this; - return temp; - } - - SelfType &operator--() - { - decrement(); - return *this; - } - - SelfType &operator++() - { - increment(); - return *this; - } - - reference operator *() const - { - return deref(); - } - }; - - -} // namespace Json - - -#endif // CPPTL_JSON_H_INCLUDED diff --git a/dependencies/include/json/writer.h b/dependencies/include/json/writer.h deleted file mode 100644 index 47893636..00000000 --- a/dependencies/include/json/writer.h +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2007-2010 Baptiste Lepilleur -// Distributed under MIT license, or public domain if desired and -// recognized in your jurisdiction. -// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE - -#ifndef JSON_WRITER_H_INCLUDED -# define JSON_WRITER_H_INCLUDED - -#if !defined(JSON_IS_AMALGAMATION) -# include "value.h" -#endif // if !defined(JSON_IS_AMALGAMATION) -# include -# include -# include - -namespace Json { - - class Value; - - /** \brief Abstract class for writers. - */ - class JSON_API Writer - { - public: - virtual ~Writer(); - - virtual std::string write( const Value &root ) = 0; - }; - - /** \brief Outputs a Value in JSON format without formatting (not human friendly). - * - * The JSON document is written in a single line. It is not intended for 'human' consumption, - * but may be usefull to support feature such as RPC where bandwith is limited. - * \sa Reader, Value - */ - class JSON_API FastWriter : public Writer - { - public: - FastWriter(); - virtual ~FastWriter(){} - - void enableYAMLCompatibility(); - - public: // overridden from Writer - virtual std::string write( const Value &root ); - - private: - void writeValue( const Value &value ); - - std::string document_; - bool yamlCompatiblityEnabled_; - }; - - /** \brief Writes a Value in JSON format in a human friendly way. - * - * The rules for line break and indent are as follow: - * - Object value: - * - if empty then print {} without indent and line break - * - if not empty the print '{', line break & indent, print one value per line - * and then unindent and line break and print '}'. - * - Array value: - * - if empty then print [] without indent and line break - * - if the array contains no object value, empty array or some other value types, - * and all the values fit on one lines, then print the array on a single line. - * - otherwise, it the values do not fit on one line, or the array contains - * object or non empty array, then print one value per line. - * - * If the Value have comments then they are outputed according to their #CommentPlacement. - * - * \sa Reader, Value, Value::setComment() - */ - class JSON_API StyledWriter: public Writer - { - public: - StyledWriter(); - virtual ~StyledWriter(){} - - public: // overridden from Writer - /** \brief Serialize a Value in JSON format. - * \param root Value to serialize. - * \return String containing the JSON document that represents the root value. - */ - virtual std::string write( const Value &root ); - - private: - void writeValue( const Value &value ); - void writeArrayValue( const Value &value ); - bool isMultineArray( const Value &value ); - void pushValue( const std::string &value ); - void writeIndent(); - void writeWithIndent( const std::string &value ); - void indent(); - void unindent(); - void writeCommentBeforeValue( const Value &root ); - void writeCommentAfterValueOnSameLine( const Value &root ); - bool hasCommentForValue( const Value &value ); - static std::string normalizeEOL( const std::string &text ); - - typedef std::vector ChildValues; - - ChildValues childValues_; - std::string document_; - std::string indentString_; - int rightMargin_; - int indentSize_; - bool addChildValues_; - }; - - /** \brief Writes a Value in JSON format in a human friendly way, - to a stream rather than to a string. - * - * The rules for line break and indent are as follow: - * - Object value: - * - if empty then print {} without indent and line break - * - if not empty the print '{', line break & indent, print one value per line - * and then unindent and line break and print '}'. - * - Array value: - * - if empty then print [] without indent and line break - * - if the array contains no object value, empty array or some other value types, - * and all the values fit on one lines, then print the array on a single line. - * - otherwise, it the values do not fit on one line, or the array contains - * object or non empty array, then print one value per line. - * - * If the Value have comments then they are outputed according to their #CommentPlacement. - * - * \param indentation Each level will be indented by this amount extra. - * \sa Reader, Value, Value::setComment() - */ - class JSON_API StyledStreamWriter - { - public: - StyledStreamWriter( std::string indentation="\t" ); - ~StyledStreamWriter(){} - - public: - /** \brief Serialize a Value in JSON format. - * \param out Stream to write to. (Can be ostringstream, e.g.) - * \param root Value to serialize. - * \note There is no point in deriving from Writer, since write() should not return a value. - */ - void write( std::ostream &out, const Value &root ); - - private: - void writeValue( const Value &value ); - void writeArrayValue( const Value &value ); - bool isMultineArray( const Value &value ); - void pushValue( const std::string &value ); - void writeIndent(); - void writeWithIndent( const std::string &value ); - void indent(); - void unindent(); - void writeCommentBeforeValue( const Value &root ); - void writeCommentAfterValueOnSameLine( const Value &root ); - bool hasCommentForValue( const Value &value ); - static std::string normalizeEOL( const std::string &text ); - - typedef std::vector ChildValues; - - ChildValues childValues_; - std::ostream* document_; - std::string indentString_; - int rightMargin_; - std::string indentation_; - bool addChildValues_; - }; - -# if defined(JSON_HAS_INT64) - std::string JSON_API valueToString( Int value ); - std::string JSON_API valueToString( UInt value ); -# endif // if defined(JSON_HAS_INT64) - std::string JSON_API valueToString( LargestInt value ); - std::string JSON_API valueToString( LargestUInt value ); - std::string JSON_API valueToString( double value ); - std::string JSON_API valueToString( bool value ); - std::string JSON_API valueToQuotedString( const char *value ); - - /// \brief Output using the StyledStreamWriter. - /// \see Json::operator>>() - std::ostream& operator<<( std::ostream&, const Value &root ); - -} // namespace Json - - - -#endif // JSON_WRITER_H_INCLUDED diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 81d0da6a..b04daa05 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -83,7 +83,7 @@ public: /// void freeObjects(); - static Hyperion* initInstance(const Json::Value& jsonConfig, const QJsonObject& qjsonConfig, const std::string configFile); + static Hyperion* initInstance(const QJsonObject& qjsonConfig, const std::string configFile); static Hyperion* getInstance(); /// @@ -304,9 +304,9 @@ private: /// /// Constructs the Hyperion instance based on the given Json configuration /// - /// @param[in] jsonConfig The Json configuration + /// @param[in] qjsonConfig The Json configuration /// - Hyperion(const Json::Value& jsonConfig, const QJsonObject& qjsonConfig, const std::string configFile); + Hyperion(const QJsonObject& qjsonConfig, const std::string configFile); /// The specifiation of the led frame construction and picture integration LedString _ledString; @@ -337,7 +337,6 @@ private: MessageForwarder * _messageForwarder; // json configuration - const Json::Value& _jsonConfig; const QJsonObject& _qjsonConfig; // the name of config file diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index 8f57eadc..85a61c23 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -2,6 +2,9 @@ #include #include +#include +#include +#include // STL incldues #include @@ -15,11 +18,10 @@ #include #include #include -#include class LedDevice; -typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const Json::Value& ); +typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& ); typedef std::map LedDeviceRegistry; /// diff --git a/include/leddevice/LedDeviceFactory.h b/include/leddevice/LedDeviceFactory.h index 725d2daf..29691a98 100644 --- a/include/leddevice/LedDeviceFactory.h +++ b/include/leddevice/LedDeviceFactory.h @@ -1,9 +1,6 @@ #pragma once -// Json includes -#include - // Leddevice includes #include @@ -23,5 +20,5 @@ public: /// @return The constructed LedDevice or nullptr if configuration is invalid. The ownership of /// the constructed LedDevice is tranferred to the caller /// - static LedDevice * construct(const Json::Value & deviceConfig, const int ledCount); + static LedDevice * construct(const QJsonObject & deviceConfig, const int ledCount); }; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 7d8ff359..ac68e7f2 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -32,11 +32,11 @@ Hyperion* Hyperion::_hyperion = nullptr; -Hyperion* Hyperion::initInstance(const Json::Value& jsonConfig, const QJsonObject& qjsonConfig, const std::string configFile) // REMOVE jsonConfig variable when the conversion from jsonCPP to QtJSON is finished +Hyperion* Hyperion::initInstance(const QJsonObject& qjsonConfig, const std::string configFile) // REMOVE jsonConfig variable when the conversion from jsonCPP to QtJSON is finished { if ( Hyperion::_hyperion != nullptr ) throw std::runtime_error("Hyperion::initInstance can be called only one time"); - Hyperion::_hyperion = new Hyperion(jsonConfig, qjsonConfig, configFile); + Hyperion::_hyperion = new Hyperion(qjsonConfig, configFile); return Hyperion::_hyperion; } @@ -514,7 +514,7 @@ MessageForwarder * Hyperion::getForwarder() return _messageForwarder; } -Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig, const std::string configFile) +Hyperion::Hyperion(const QJsonObject &qjsonConfig, const std::string configFile) : _ledString(createLedString(qjsonConfig["leds"], createColorOrder(qjsonConfig["device"].toObject()))) , _ledStringClone(createLedStringClone(qjsonConfig["leds"], createColorOrder(qjsonConfig["device"].toObject()))) , _muxer(_ledString.leds().size()) @@ -522,7 +522,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig , _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), qjsonConfig["color"].toObject())) , _effectEngine(nullptr) , _messageForwarder(createMessageForwarder(qjsonConfig["forwarder"].toObject())) - , _jsonConfig(jsonConfig) , _qjsonConfig(qjsonConfig) , _configFile(configFile) , _timer() @@ -566,7 +565,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig getComponentRegister().componentStateChanged(hyperion::COMP_FORWARDER, _messageForwarder->forwardingEnabled()); // initialize leddevices - _device = LedDeviceFactory::construct(jsonConfig["device"],_hwLedCount); + _device = LedDeviceFactory::construct(qjsonConfig["device"].toObject(),_hwLedCount); _deviceSmooth = createColorSmoothing(qjsonConfig["smoothing"].toObject(), _device); getComponentRegister().componentStateChanged(hyperion::COMP_SMOOTHING, _deviceSmooth->componentState()); diff --git a/libsrc/hyperion/LedString.cpp b/libsrc/hyperion/LedString.cpp index a44a4dc5..894d6dd5 100644 --- a/libsrc/hyperion/LedString.cpp +++ b/libsrc/hyperion/LedString.cpp @@ -3,9 +3,6 @@ #include #include -// Json includes -#include - // hyperion includes #include diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 676f8e29..ed710eed 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -348,7 +348,7 @@ void JsonClientConnection::handleColorCommand(const QJsonObject& message, const std::vector colorData(_hyperion->getLedCount()); const QJsonArray & jsonColor = message["color"].toArray(); - Json::UInt i = 0; + unsigned int i = 0; for (; i < unsigned(jsonColor.size()/3) && i < _hyperion->getLedCount(); ++i) { colorData[i].red = uint8_t(jsonColor.at(3u*i).toInt()); diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 51cc5ace..ce6763e7 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -5,8 +5,6 @@ #include #include #include -#include -#include LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry(); std::string LedDevice::_activeDevice = ""; diff --git a/libsrc/leddevice/LedDeviceAPA102.cpp b/libsrc/leddevice/LedDeviceAPA102.cpp index 957fbf18..af647f0b 100644 --- a/libsrc/leddevice/LedDeviceAPA102.cpp +++ b/libsrc/leddevice/LedDeviceAPA102.cpp @@ -1,17 +1,17 @@ #include "LedDeviceAPA102.h" -LedDeviceAPA102::LedDeviceAPA102(const Json::Value &deviceConfig) +LedDeviceAPA102::LedDeviceAPA102(const QJsonObject &deviceConfig) : ProviderSpi() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceAPA102::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceAPA102::construct(const QJsonObject &deviceConfig) { return new LedDeviceAPA102(deviceConfig); } -bool LedDeviceAPA102::init(const Json::Value &deviceConfig) +bool LedDeviceAPA102::init(const QJsonObject &deviceConfig) { ProviderSpi::init(deviceConfig); _latchTime_ns = 500000; // fixed latchtime diff --git a/libsrc/leddevice/LedDeviceAPA102.h b/libsrc/leddevice/LedDeviceAPA102.h index e115252c..4bb84f62 100644 --- a/libsrc/leddevice/LedDeviceAPA102.h +++ b/libsrc/leddevice/LedDeviceAPA102.h @@ -13,12 +13,12 @@ public: /// /// Constructs specific LedDevice /// - LedDeviceAPA102(const Json::Value &deviceConfig); + LedDeviceAPA102(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceAdalight.cpp b/libsrc/leddevice/LedDeviceAdalight.cpp index de350b14..9d6356cb 100644 --- a/libsrc/leddevice/LedDeviceAdalight.cpp +++ b/libsrc/leddevice/LedDeviceAdalight.cpp @@ -1,18 +1,18 @@ #include "LedDeviceAdalight.h" -LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig) +LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig) : ProviderRs232() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceAdalight::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceAdalight::construct(const QJsonObject &deviceConfig) { return new LedDeviceAdalight(deviceConfig); } -bool LedDeviceAdalight::init(const Json::Value &deviceConfig) +bool LedDeviceAdalight::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceAdalight.h b/libsrc/leddevice/LedDeviceAdalight.h index 91b9483c..b44627e8 100644 --- a/libsrc/leddevice/LedDeviceAdalight.h +++ b/libsrc/leddevice/LedDeviceAdalight.h @@ -15,12 +15,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceAdalight(const Json::Value &deviceConfig); + LedDeviceAdalight(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.cpp b/libsrc/leddevice/LedDeviceAdalightApa102.cpp index ae564b21..030dd8a8 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.cpp +++ b/libsrc/leddevice/LedDeviceAdalightApa102.cpp @@ -1,17 +1,17 @@ #include "LedDeviceAdalightApa102.h" -LedDeviceAdalightApa102::LedDeviceAdalightApa102(const Json::Value &deviceConfig) +LedDeviceAdalightApa102::LedDeviceAdalightApa102(const QJsonObject &deviceConfig) : ProviderRs232() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceAdalightApa102::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceAdalightApa102::construct(const QJsonObject &deviceConfig) { return new LedDeviceAdalightApa102(deviceConfig); } -bool LedDeviceAdalightApa102::init(const Json::Value &deviceConfig) +bool LedDeviceAdalightApa102::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.h b/libsrc/leddevice/LedDeviceAdalightApa102.h index ac07f38c..00c59a44 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.h +++ b/libsrc/leddevice/LedDeviceAdalightApa102.h @@ -17,12 +17,12 @@ public: /// @param outputDevice The name of the output device (eg '/dev/ttyS0') /// @param baudrate The used baudrate for writing to the output device /// - LedDeviceAdalightApa102(const Json::Value &deviceConfig); + LedDeviceAdalightApa102(const QJsonObject &deviceConfig); /// create leddevice when type in config is set to this type - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceAtmo.cpp b/libsrc/leddevice/LedDeviceAtmo.cpp index d832f9a5..78418fb9 100644 --- a/libsrc/leddevice/LedDeviceAtmo.cpp +++ b/libsrc/leddevice/LedDeviceAtmo.cpp @@ -1,18 +1,18 @@ // hyperion local includes #include "LedDeviceAtmo.h" -LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig) +LedDeviceAtmo::LedDeviceAtmo(const QJsonObject &deviceConfig) : ProviderRs232() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceAtmo::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceAtmo::construct(const QJsonObject &deviceConfig) { return new LedDeviceAtmo(deviceConfig); } -bool LedDeviceAtmo::init(const Json::Value &deviceConfig) +bool LedDeviceAtmo::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); @@ -36,4 +36,3 @@ int LedDeviceAtmo::write(const std::vector &ledValues) memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledCount * sizeof(ColorRgb)); return writeBytes(_ledBuffer.size(), _ledBuffer.data()); } - diff --git a/libsrc/leddevice/LedDeviceAtmo.h b/libsrc/leddevice/LedDeviceAtmo.h index 089c64ac..475c024a 100644 --- a/libsrc/leddevice/LedDeviceAtmo.h +++ b/libsrc/leddevice/LedDeviceAtmo.h @@ -14,12 +14,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceAtmo(const Json::Value &deviceConfig); + LedDeviceAtmo(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.cpp b/libsrc/leddevice/LedDeviceAtmoOrb.cpp index 033c48eb..64773e85 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.cpp +++ b/libsrc/leddevice/LedDeviceAtmoOrb.cpp @@ -16,7 +16,7 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) { // Not implemented } -LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig) +LedDeviceAtmoOrb::LedDeviceAtmoOrb(const QJsonObject &deviceConfig) : LedDevice() { init(deviceConfig); @@ -29,16 +29,16 @@ LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig) joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress); } -bool LedDeviceAtmoOrb::init(const Json::Value &deviceConfig) +bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig) { - _multicastGroup = deviceConfig["output"].asString().c_str(); - _useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool(); - _transitiontime = deviceConfig.get("transitiontime", 0).asInt(); - _skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt(); - _multiCastGroupPort = deviceConfig.get("port", 49692).asInt(); - _numLeds = deviceConfig.get("numLeds", 24).asInt(); + _multicastGroup = deviceConfig["output"].toString().toStdString().c_str(); + _useOrbSmoothing = deviceConfig["useOrbSmoothing"].toBool(false); + _transitiontime = deviceConfig["transitiontime"].toInt(0); + _skipSmoothingDiff = deviceConfig["skipSmoothingDiff"].toInt(0); + _multiCastGroupPort = deviceConfig["port"].toInt(49692); + _numLeds = deviceConfig["numLeds"].toInt(24); - const std::string orbId = deviceConfig["orbIds"].asString(); + const std::string orbId = deviceConfig["orbIds"].toString().toStdString(); _orbIds.clear(); // If we find multiple Orb ids separate them and add to list @@ -62,7 +62,7 @@ bool LedDeviceAtmoOrb::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceAtmoOrb::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig) { return new LedDeviceAtmoOrb(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.h b/libsrc/leddevice/LedDeviceAtmoOrb.h index b95342f6..ecb26eea 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.h +++ b/libsrc/leddevice/LedDeviceAtmoOrb.h @@ -46,17 +46,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceAtmoOrb(const Json::Value &deviceConfig); + LedDeviceAtmoOrb(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Destructor of this device /// @@ -118,4 +118,4 @@ private: /// @param bytes the byte array containing command to send over multicast /// void sendCommand(const QByteArray &bytes); -}; \ No newline at end of file +}; diff --git a/libsrc/leddevice/LedDeviceDMX.cpp b/libsrc/leddevice/LedDeviceDMX.cpp index 22661918..1c793d21 100644 --- a/libsrc/leddevice/LedDeviceDMX.cpp +++ b/libsrc/leddevice/LedDeviceDMX.cpp @@ -2,7 +2,7 @@ #include #include -LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig) +LedDeviceDMX::LedDeviceDMX(const QJsonObject &deviceConfig) : ProviderRs232() , _dmxDeviceType(0) , _dmxStart(1) @@ -11,7 +11,7 @@ LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig) , _dmxChannelCount(0) { ProviderRs232::init(deviceConfig); - std::string _dmxString = deviceConfig.get("dmxdevice", "invalid").asString(); + std::string _dmxString = deviceConfig["dmxdevice"].toString("invalid").toStdString(); if (_dmxString == "raw") { _dmxDeviceType = 0; @@ -42,7 +42,7 @@ LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig) _ledBuffer[0] = 0x00; // NULL START code } -LedDevice* LedDeviceDMX::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceDMX::construct(const QJsonObject &deviceConfig) { return new LedDeviceDMX(deviceConfig); } @@ -85,4 +85,3 @@ int LedDeviceDMX::write(const std::vector &ledValues) return writeBytes(_dmxChannelCount, _ledBuffer.data()); } - diff --git a/libsrc/leddevice/LedDeviceDMX.h b/libsrc/leddevice/LedDeviceDMX.h index 7e4017ff..ee9de606 100644 --- a/libsrc/leddevice/LedDeviceDMX.h +++ b/libsrc/leddevice/LedDeviceDMX.h @@ -14,10 +14,10 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceDMX(const Json::Value &deviceConfig); + LedDeviceDMX(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 95c43571..72c60dd9 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -57,14 +57,14 @@ #include "LedDeviceWS281x.h" #endif -LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig, const int ledCount) +LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const int ledCount) { Logger * log = Logger::getInstance("LedDevice"); - std::stringstream ss; - ss << deviceConfig; - Info(log, "configuration: %s ", ss.str().c_str()); + QJsonDocument config(deviceConfig); + QString ss(config.toJson(QJsonDocument::Indented)); + Info(log, "configuration: %s ", ss.toUtf8().constData()); - std::string type = deviceConfig.get("type", "UNSPECIFIED").asString(); + std::string type = deviceConfig["type"].toString("UNSPECIFIED").toStdString(); std::transform(type.begin(), type.end(), type.begin(), ::tolower); // set amount of led to leddevice @@ -148,8 +148,8 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig, const { Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what()); - const Json::Value dummyDeviceConfig; - device = LedDeviceFile::construct(Json::nullValue); + const QJsonObject dummyDeviceConfig; + device = LedDeviceFile::construct(QJsonObject()); } device->open(); diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index 3b5dab83..1374d093 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -6,7 +6,7 @@ static const unsigned OPC_SYS_EX = 255; // OPC command codes static const unsigned OPC_HEADER_SIZE = 4; // OPC header size -LedDeviceFadeCandy::LedDeviceFadeCandy(const Json::Value &deviceConfig) +LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject &deviceConfig) : LedDevice() { _deviceReady = init(deviceConfig); @@ -18,13 +18,13 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy() _client.close(); } -LedDevice* LedDeviceFadeCandy::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceFadeCandy::construct(const QJsonObject &deviceConfig) { return new LedDeviceFadeCandy(deviceConfig); } -bool LedDeviceFadeCandy::init(const Json::Value &deviceConfig) +bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig) { _client.close(); @@ -34,26 +34,26 @@ bool LedDeviceFadeCandy::init(const Json::Value &deviceConfig) return false; } - _host = deviceConfig.get("output", "127.0.0.1").asString(); - _port = deviceConfig.get("port", 7890).asInt(); - _channel = deviceConfig.get("channel", 0).asInt(); - _gamma = deviceConfig.get("gamma", 1.0).asDouble(); - _noDither = ! deviceConfig.get("dither", false).asBool(); - _noInterp = ! deviceConfig.get("interpolation", false).asBool(); - _manualLED = deviceConfig.get("manualLed", false).asBool(); - _ledOnOff = deviceConfig.get("ledOn", false).asBool(); - _setFcConfig = deviceConfig.get("setFcConfig", false).asBool(); + _host = deviceConfig["output"].toString("127.0.0.1").toStdString(); + _port = deviceConfig["port"].toInt(7890); + _channel = deviceConfig["channel"].toInt(0); + _gamma = deviceConfig["gamma"].toDouble(1.0); + _noDither = ! deviceConfig["dither"].toBool(false); + _noInterp = ! deviceConfig["interpolation"].toBool(false); + _manualLED = deviceConfig["manualLed"].toBool(false); + _ledOnOff = deviceConfig["ledOn"].toBool(false); + _setFcConfig = deviceConfig["setFcConfig"].toBool(false); _whitePoint_r = 1.0; _whitePoint_g = 1.0; _whitePoint_b = 1.0; - const Json::Value whitePointConfig = deviceConfig["whitePoint"]; - if ( whitePointConfig.isArray() && whitePointConfig.size() == 3 ) + const QJsonArray whitePointConfig = deviceConfig["whitePoint"].toArray(); + if ( !whitePointConfig.isEmpty() && whitePointConfig.size() == 3 ) { - _whitePoint_r = whitePointConfig[0].asDouble(); - _whitePoint_g = whitePointConfig[1].asDouble(); - _whitePoint_b = whitePointConfig[2].asDouble(); + _whitePoint_r = whitePointConfig[0].toDouble(); + _whitePoint_g = whitePointConfig[1].toDouble(); + _whitePoint_b = whitePointConfig[2].toDouble(); } _opc_data.resize( _ledRGBCount + OPC_HEADER_SIZE ); diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h index 19030978..e00bcc5e 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.h +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -38,7 +38,7 @@ public: /// /// @param deviceConfig json config for fadecandy /// - LedDeviceFadeCandy(const Json::Value &deviceConfig); + LedDeviceFadeCandy(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice; closes the tcp client @@ -46,14 +46,14 @@ public: virtual ~LedDeviceFadeCandy(); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// /// Writes the led color values to the led-device @@ -111,4 +111,3 @@ private: void sendFadeCandyConfiguration(); }; - diff --git a/libsrc/leddevice/LedDeviceFile.cpp b/libsrc/leddevice/LedDeviceFile.cpp index d39a0475..b80109bf 100644 --- a/libsrc/leddevice/LedDeviceFile.cpp +++ b/libsrc/leddevice/LedDeviceFile.cpp @@ -1,6 +1,6 @@ #include "LedDeviceFile.h" -LedDeviceFile::LedDeviceFile(const Json::Value &deviceConfig) +LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig) : LedDevice() { init(deviceConfig); @@ -10,19 +10,19 @@ LedDeviceFile::~LedDeviceFile() { } -LedDevice* LedDeviceFile::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig) { return new LedDeviceFile(deviceConfig); } -bool LedDeviceFile::init(const Json::Value &deviceConfig) +bool LedDeviceFile::init(const QJsonObject &deviceConfig) { if ( _ofs.is_open() ) { _ofs.close(); } - std::string fileName = deviceConfig.get("output","/dev/null").asString(); + std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString(); _ofs.open( fileName.c_str() ); return true; diff --git a/libsrc/leddevice/LedDeviceFile.h b/libsrc/leddevice/LedDeviceFile.h index e22ccc4c..4a9e9430 100644 --- a/libsrc/leddevice/LedDeviceFile.h +++ b/libsrc/leddevice/LedDeviceFile.h @@ -18,7 +18,7 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceFile(const Json::Value &deviceConfig); + LedDeviceFile(const QJsonObject &deviceConfig); /// /// Destructor of this test-device @@ -26,14 +26,14 @@ public: virtual ~LedDeviceFile(); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); protected: /// diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp index 20056310..08155ee1 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp @@ -11,7 +11,7 @@ uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc; std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller"; -LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const Json::Value &deviceConfig) +LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig) : LedDevice() , _libusbContext(nullptr) , _deviceHandle(nullptr) @@ -37,9 +37,9 @@ LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp() } } -bool LedDeviceHyperionUsbasp::init(const Json::Value &deviceConfig) +bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig) { - std::string ledType = deviceConfig.get("output", "ws2801").asString(); + std::string ledType = deviceConfig["output"].toString("ws2801").toStdString(); if (ledType != "ws2801" && ledType != "ws2812") { throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'."); @@ -50,7 +50,7 @@ bool LedDeviceHyperionUsbasp::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceHyperionUsbasp::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceHyperionUsbasp::construct(const QJsonObject &deviceConfig) { return new LedDeviceHyperionUsbasp(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.h b/libsrc/leddevice/LedDeviceHyperionUsbasp.h index f2cc709f..72f61753 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.h +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.h @@ -28,17 +28,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceHyperionUsbasp(const Json::Value &deviceConfig); + LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open diff --git a/libsrc/leddevice/LedDeviceLightpack.cpp b/libsrc/leddevice/LedDeviceLightpack.cpp index 8cfbdfcf..018e08d8 100644 --- a/libsrc/leddevice/LedDeviceLightpack.cpp +++ b/libsrc/leddevice/LedDeviceLightpack.cpp @@ -45,7 +45,7 @@ LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber) { } -LedDeviceLightpack::LedDeviceLightpack(const Json::Value &deviceConfig) +LedDeviceLightpack::LedDeviceLightpack(const QJsonObject &deviceConfig) : LedDevice() { init(deviceConfig); @@ -69,14 +69,14 @@ LedDeviceLightpack::~LedDeviceLightpack() } } -bool LedDeviceLightpack::init(const Json::Value &deviceConfig) +bool LedDeviceLightpack::init(const QJsonObject &deviceConfig) { - _serialNumber = deviceConfig.get("output", "").asString(); + _serialNumber = deviceConfig["output"].toString("").toStdString(); return true; } -LedDevice* LedDeviceLightpack::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceLightpack::construct(const QJsonObject &deviceConfig) { return new LedDeviceLightpack(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceLightpack.h b/libsrc/leddevice/LedDeviceLightpack.h index f0441400..47cfb83c 100644 --- a/libsrc/leddevice/LedDeviceLightpack.h +++ b/libsrc/leddevice/LedDeviceLightpack.h @@ -26,17 +26,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceLightpack(const Json::Value &deviceConfig); + LedDeviceLightpack(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open diff --git a/libsrc/leddevice/LedDeviceLpd6803.cpp b/libsrc/leddevice/LedDeviceLpd6803.cpp index ec2fde74..7762f293 100644 --- a/libsrc/leddevice/LedDeviceLpd6803.cpp +++ b/libsrc/leddevice/LedDeviceLpd6803.cpp @@ -1,17 +1,17 @@ #include "LedDeviceLpd6803.h" -LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig) +LedDeviceLpd6803::LedDeviceLpd6803(const QJsonObject &deviceConfig) : ProviderSpi() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceLpd6803::construct(const QJsonObject &deviceConfig) { return new LedDeviceLpd6803(deviceConfig); } -bool LedDeviceLpd6803::init(const Json::Value &deviceConfig) +bool LedDeviceLpd6803::init(const QJsonObject &deviceConfig) { ProviderSpi::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceLpd6803.h b/libsrc/leddevice/LedDeviceLpd6803.h index cf61ec10..fd0da312 100644 --- a/libsrc/leddevice/LedDeviceLpd6803.h +++ b/libsrc/leddevice/LedDeviceLpd6803.h @@ -22,12 +22,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceLpd6803(const Json::Value &deviceConfig); + LedDeviceLpd6803(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceLpd8806.cpp b/libsrc/leddevice/LedDeviceLpd8806.cpp index 05053268..a3bddc1b 100644 --- a/libsrc/leddevice/LedDeviceLpd8806.cpp +++ b/libsrc/leddevice/LedDeviceLpd8806.cpp @@ -1,17 +1,17 @@ #include "LedDeviceLpd8806.h" -LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig) +LedDeviceLpd8806::LedDeviceLpd8806(const QJsonObject &deviceConfig) : ProviderSpi() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceLpd8806::construct(const QJsonObject &deviceConfig) { return new LedDeviceLpd8806(deviceConfig); } -bool LedDeviceLpd8806::init(const Json::Value &deviceConfig) +bool LedDeviceLpd8806::init(const QJsonObject &deviceConfig) { ProviderSpi::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceLpd8806.h b/libsrc/leddevice/LedDeviceLpd8806.h index 5256a68e..b921a30d 100644 --- a/libsrc/leddevice/LedDeviceLpd8806.h +++ b/libsrc/leddevice/LedDeviceLpd8806.h @@ -83,12 +83,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceLpd8806(const Json::Value &deviceConfig); + LedDeviceLpd8806(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.cpp b/libsrc/leddevice/LedDeviceMultiLightpack.cpp index 2092bcb1..cf211c88 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.cpp +++ b/libsrc/leddevice/LedDeviceMultiLightpack.cpp @@ -17,7 +17,7 @@ bool compareLightpacks(LedDeviceLightpack * lhs, LedDeviceLightpack * rhs) return lhs->getSerialNumber() < rhs->getSerialNumber(); } -LedDeviceMultiLightpack::LedDeviceMultiLightpack(const Json::Value &) +LedDeviceMultiLightpack::LedDeviceMultiLightpack(const QJsonObject &) : LedDevice() , _lightpacks() { @@ -31,7 +31,7 @@ LedDeviceMultiLightpack::~LedDeviceMultiLightpack() } } -LedDevice* LedDeviceMultiLightpack::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceMultiLightpack::construct(const QJsonObject &deviceConfig) { return new LedDeviceMultiLightpack(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.h b/libsrc/leddevice/LedDeviceMultiLightpack.h index dcd7f50a..0b285fd3 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.h +++ b/libsrc/leddevice/LedDeviceMultiLightpack.h @@ -22,9 +22,7 @@ public: /// /// Constructs specific LedDevice /// - /// @param deviceConfig json device config - /// - LedDeviceMultiLightpack(const Json::Value &); + LedDeviceMultiLightpack(const QJsonObject &); /// /// Destructor of the LedDevice; closes the output device if it is open @@ -32,7 +30,7 @@ public: virtual ~LedDeviceMultiLightpack(); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Opens and configures the output device7 diff --git a/libsrc/leddevice/LedDeviceP9813.cpp b/libsrc/leddevice/LedDeviceP9813.cpp index a50086e5..bc76aea0 100644 --- a/libsrc/leddevice/LedDeviceP9813.cpp +++ b/libsrc/leddevice/LedDeviceP9813.cpp @@ -1,17 +1,17 @@ #include "LedDeviceP9813.h" -LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig) +LedDeviceP9813::LedDeviceP9813(const QJsonObject &deviceConfig) : ProviderSpi() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceP9813::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig) { return new LedDeviceP9813(deviceConfig); } -bool LedDeviceP9813::init(const Json::Value &deviceConfig) +bool LedDeviceP9813::init(const QJsonObject &deviceConfig) { ProviderSpi::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceP9813.h b/libsrc/leddevice/LedDeviceP9813.h index df16102c..af3fb337 100644 --- a/libsrc/leddevice/LedDeviceP9813.h +++ b/libsrc/leddevice/LedDeviceP9813.h @@ -14,12 +14,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceP9813(const Json::Value &deviceConfig); + LedDeviceP9813(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDevicePaintpack.cpp b/libsrc/leddevice/LedDevicePaintpack.cpp index 118b660f..8a984dcb 100644 --- a/libsrc/leddevice/LedDevicePaintpack.cpp +++ b/libsrc/leddevice/LedDevicePaintpack.cpp @@ -1,7 +1,7 @@ #include "LedDevicePaintpack.h" // Use out report HID device -LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig) +LedDevicePaintpack::LedDevicePaintpack(const QJsonObject &deviceConfig) : ProviderHID() { ProviderHID::init(deviceConfig); @@ -12,7 +12,7 @@ LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig) _ledBuffer[1] = 0; } -LedDevice* LedDevicePaintpack::construct(const Json::Value &deviceConfig) +LedDevice* LedDevicePaintpack::construct(const QJsonObject &deviceConfig) { return new LedDevicePaintpack(deviceConfig); } diff --git a/libsrc/leddevice/LedDevicePaintpack.h b/libsrc/leddevice/LedDevicePaintpack.h index 0b06c971..1c2eb9d7 100644 --- a/libsrc/leddevice/LedDevicePaintpack.h +++ b/libsrc/leddevice/LedDevicePaintpack.h @@ -14,10 +14,10 @@ public: /// /// @param deviceConfig json device config /// - LedDevicePaintpack(const Json::Value &deviceConfig); + LedDevicePaintpack(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index 88a7876e..a2b308b0 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -161,7 +161,7 @@ CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue) return xy; } -LedDevicePhilipsHue::LedDevicePhilipsHue(const Json::Value &deviceConfig) +LedDevicePhilipsHue::LedDevicePhilipsHue(const QJsonObject &deviceConfig) : LedDevice() { _deviceReady = init(deviceConfig); @@ -177,22 +177,23 @@ LedDevicePhilipsHue::~LedDevicePhilipsHue() delete manager; } -bool LedDevicePhilipsHue::init(const Json::Value &deviceConfig) +bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig) { - host = deviceConfig["output"].asString().c_str(); - username = deviceConfig.get("username", "newdeveloper").asString().c_str(); - switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool(); - transitiontime = deviceConfig.get("transitiontime", 1).asInt(); + host = deviceConfig["output"].toString().toStdString().c_str(); + username = deviceConfig["username"].toString("newdeveloper").toStdString().c_str(); + switchOffOnBlack = deviceConfig["switchOffOnBlack"].toBool(true); + transitiontime = deviceConfig["transitiontime"].toInt(1); lightIds.clear(); - for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) + QJsonArray lArray = deviceConfig["lightIds"].toArray(); + for(int i = 0; i < lArray.size(); i++) { - lightIds.push_back(deviceConfig["lightIds"][i].asInt()); + lightIds.push_back(lArray[i].toInt()); } return true; } -LedDevice* LedDevicePhilipsHue::construct(const Json::Value &deviceConfig) +LedDevice* LedDevicePhilipsHue::construct(const QJsonObject &deviceConfig) { return new LedDevicePhilipsHue(deviceConfig); } @@ -319,26 +320,34 @@ QString LedDevicePhilipsHue::getUrl(QString route) void LedDevicePhilipsHue::saveStates(unsigned int nLights) { + QJsonParseError error; + QJsonDocument reader; + QJsonObject json; + QByteArray response; + // Clear saved lamps. lights.clear(); - // Use json parser to parse reponse. - Json::Reader reader; - Json::FastWriter writer; + // Read light ids if none have been supplied by the user. if (lightIds.size() != nLights) { lightIds.clear(); // - QByteArray response = get("lights"); - Json::Value json; - if (!reader.parse(QString(response).toStdString(), json)) + response = get("lights"); + // Use QJsonDocument to parse reponse. + reader = QJsonDocument::fromJson(response, &error); + + if (error.error != QJsonParseError::NoError) { throw std::runtime_error(("No lights found at " + getUrl("lights")).toStdString()); } + + json = reader.object(); + // Loop over all children. - for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++) + for (QJsonObject::iterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++) { - int lightId = atoi(it.key().asCString()); + int lightId = atoi(it.key().toStdString().c_str()); lightIds.push_back(lightId); Debug(_log, "nLights=%d: found light with id %d.", nLights, lightId); } @@ -352,36 +361,40 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) for (unsigned int i = 0; i < nLights; i++) { // Read the response. - QByteArray response = get(getRoute(lightIds.at(i))); + response = get(getRoute(lightIds.at(i))); // Parse JSON. - Json::Value json; - if (!reader.parse(QString(response).toStdString(), json)) + reader = QJsonDocument::fromJson(response, &error); + + if (error.error != QJsonParseError::NoError) { // Error occured, break loop. Error(_log, "saveStates(nLights=%d): got invalid response from light %s.", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str()); break; } + // Get state object values which are subject to change. - Json::Value state(Json::objectValue); - if (!json.isMember("state")) + QJsonObject state; + if (!json.contains("state")) { Error(_log, "saveStates(nLights=%d): got no state for light from %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str()); break; } - if (!json["state"].isMember("on")) + if (!json["state"].toObject().contains("on")) { Error(_log, "saveStates(nLights=%d,): got no valid state from light %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str()); break; } - state["on"] = json["state"]["on"]; - if (json["state"]["on"] == true) + state["on"] = json["state"].toObject()["on"]; + if (json["state"].toObject()["on"].toBool() == true) { - state["xy"] = json["state"]["xy"]; - state["bri"] = json["state"]["bri"]; + state["xy"] = json["state"].toObject()["xy"]; + state["bri"] = json["state"].toObject()["bri"]; } // Determine the model id. - QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", ""); - QString originalState = QString(writer.write(state).c_str()).trimmed(); + QJsonDocument mId(json["modelid"].toObject()); + QString modelId = mId.toJson().trimmed().replace("\"", ""); + QJsonDocument st(state); + QString originalState = mId.toJson().trimmed(); // Save state object. lights.push_back(PhilipsHueLight(lightIds.at(i), originalState, modelId)); } diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 661def86..4d574fd1 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -115,7 +115,7 @@ public: /// /// @param deviceConfig json device config /// - LedDevicePhilipsHue(const Json::Value &deviceConfig); + LedDevicePhilipsHue(const QJsonObject &deviceConfig); /// /// Destructor of this device @@ -127,10 +127,10 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// Restores the original state of the leds. virtual int switchOff(); diff --git a/libsrc/leddevice/LedDevicePiBlaster.cpp b/libsrc/leddevice/LedDevicePiBlaster.cpp index 90c6b3b3..402d7ecd 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.cpp +++ b/libsrc/leddevice/LedDevicePiBlaster.cpp @@ -9,7 +9,7 @@ // Local LedDevice includes #include "LedDevicePiBlaster.h" -LedDevicePiBlaster::LedDevicePiBlaster(const Json::Value &deviceConfig) +LedDevicePiBlaster::LedDevicePiBlaster(const QJsonObject &deviceConfig) : _fid(nullptr) { signal(SIGPIPE, SIG_IGN); @@ -40,22 +40,23 @@ LedDevicePiBlaster::~LedDevicePiBlaster() } -bool LedDevicePiBlaster::init(const Json::Value &deviceConfig) +bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig) { - _deviceName = deviceConfig.get("output", "").asString(); - Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue); + _deviceName = deviceConfig["output"].toString("").toStdString(); + QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray(); - if (gpioMapping.isNull()) + if (gpioMapping.isEmpty()) { throw std::runtime_error("Piblaster: no gpiomap defined."); } // walk through the json config and populate the mapping tables - for (const Json::Value& gpioMap : gpioMapping) + for(QJsonArray::const_iterator gpioArray = gpioMapping.begin(); gpioArray != gpioMapping.end(); ++gpioArray) { - const int gpio = gpioMap.get("gpio",-1).asInt(); - const int ledindex = gpioMap.get("ledindex",-1).asInt(); - const std::string ledcolor = gpioMap.get("ledcolor","z").asString(); + const QJsonObject value = (*gpioArray).toObject(); + const int gpio = value["gpio"].toInt(-1); + const int ledindex = value["ledindex"].toInt(-1); + const std::string ledcolor = value["ledcolor"].toString("z").toStdString(); // ignore missing/invalid settings if ( (gpio >= 0) && (gpio < signed(TABLE_SZ)) && (ledindex >= 0) ){ @@ -69,7 +70,7 @@ bool LedDevicePiBlaster::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDevicePiBlaster::construct(const Json::Value &deviceConfig) +LedDevice* LedDevicePiBlaster::construct(const QJsonObject &deviceConfig) { return new LedDevicePiBlaster(deviceConfig); } @@ -153,4 +154,3 @@ int LedDevicePiBlaster::write(const std::vector & ledValues) return 0; } - diff --git a/libsrc/leddevice/LedDevicePiBlaster.h b/libsrc/leddevice/LedDevicePiBlaster.h index 8ba3a612..e42479c7 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.h +++ b/libsrc/leddevice/LedDevicePiBlaster.h @@ -15,7 +15,7 @@ public: /// /// @param deviceConfig json device config /// - LedDevicePiBlaster(const Json::Value &deviceConfig); + LedDevicePiBlaster(const QJsonObject &deviceConfig); virtual ~LedDevicePiBlaster(); @@ -24,10 +24,10 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Attempts to open the piblaster-device. This will only succeed if the device is not yet open diff --git a/libsrc/leddevice/LedDeviceRawHID.cpp b/libsrc/leddevice/LedDeviceRawHID.cpp index c74f94da..e1d48771 100644 --- a/libsrc/leddevice/LedDeviceRawHID.cpp +++ b/libsrc/leddevice/LedDeviceRawHID.cpp @@ -1,7 +1,7 @@ #include "LedDeviceRawHID.h" // Use feature report HID device -LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig) +LedDeviceRawHID::LedDeviceRawHID(const QJsonObject &deviceConfig) : ProviderHID() , _timer() { @@ -18,7 +18,7 @@ LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig) _timer.start(); } -LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig) { return new LedDeviceRawHID(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceRawHID.h b/libsrc/leddevice/LedDeviceRawHID.h index f77944ef..f6c31582 100644 --- a/libsrc/leddevice/LedDeviceRawHID.h +++ b/libsrc/leddevice/LedDeviceRawHID.h @@ -19,10 +19,10 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceRawHID(const Json::Value &deviceConfig); + LedDeviceRawHID(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private slots: /// Write the last data to the leds again diff --git a/libsrc/leddevice/LedDeviceSedu.cpp b/libsrc/leddevice/LedDeviceSedu.cpp index 503c4569..304fe9ff 100644 --- a/libsrc/leddevice/LedDeviceSedu.cpp +++ b/libsrc/leddevice/LedDeviceSedu.cpp @@ -6,18 +6,18 @@ struct FrameSpec size_t size; }; -LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig) +LedDeviceSedu::LedDeviceSedu(const QJsonObject &deviceConfig) : ProviderRs232() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceSedu::construct(const QJsonObject &deviceConfig) { return new LedDeviceSedu(deviceConfig); } -bool LedDeviceSedu::init(const Json::Value &deviceConfig) +bool LedDeviceSedu::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceSedu.h b/libsrc/leddevice/LedDeviceSedu.h index 341d1bc0..02d2fac2 100644 --- a/libsrc/leddevice/LedDeviceSedu.h +++ b/libsrc/leddevice/LedDeviceSedu.h @@ -14,12 +14,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceSedu(const Json::Value &deviceConfig); + LedDeviceSedu(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceSk6812SPI.cpp b/libsrc/leddevice/LedDeviceSk6812SPI.cpp index d213c8b0..06c9e8f9 100644 --- a/libsrc/leddevice/LedDeviceSk6812SPI.cpp +++ b/libsrc/leddevice/LedDeviceSk6812SPI.cpp @@ -1,6 +1,6 @@ #include "LedDeviceSk6812SPI.h" -LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig) +LedDeviceSk6812SPI::LedDeviceSk6812SPI(const QJsonObject &deviceConfig) : ProviderSpi() , _whiteAlgorithm(RGBW::INVALID) , bitpair_to_byte { @@ -13,14 +13,14 @@ LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig) _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceSk6812SPI::construct(const QJsonObject &deviceConfig) { return new LedDeviceSk6812SPI(deviceConfig); } -bool LedDeviceSk6812SPI::init(const Json::Value &deviceConfig) +bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig) { - std::string whiteAlgorithm = deviceConfig.get("white_algorithm","white_off").asString(); + std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString(); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); if (_whiteAlgorithm == RGBW::INVALID) diff --git a/libsrc/leddevice/LedDeviceSk6812SPI.h b/libsrc/leddevice/LedDeviceSk6812SPI.h index 03757483..1564b6e1 100644 --- a/libsrc/leddevice/LedDeviceSk6812SPI.h +++ b/libsrc/leddevice/LedDeviceSk6812SPI.h @@ -14,17 +14,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceSk6812SPI(const Json::Value &deviceConfig); + LedDeviceSk6812SPI(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceTinkerforge.cpp b/libsrc/leddevice/LedDeviceTinkerforge.cpp index d9dc512c..b251c620 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.cpp +++ b/libsrc/leddevice/LedDeviceTinkerforge.cpp @@ -9,7 +9,7 @@ static const unsigned MAX_NUM_LEDS = 320; static const unsigned MAX_NUM_LEDS_SETTABLE = 16; -LedDeviceTinkerforge::LedDeviceTinkerforge(const Json::Value &deviceConfig) +LedDeviceTinkerforge::LedDeviceTinkerforge(const QJsonObject &deviceConfig) : LedDevice() , _ipConnection(nullptr) , _ledStrip(nullptr) @@ -31,12 +31,12 @@ LedDeviceTinkerforge::~LedDeviceTinkerforge() delete _ledStrip; } -bool LedDeviceTinkerforge::init(const Json::Value &deviceConfig) +bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig) { - _host = deviceConfig.get("output", "127.0.0.1").asString(); - _port = deviceConfig.get("port", 4223).asInt(); - _uid = deviceConfig["uid"].asString(); - _interval = deviceConfig["rate"].asInt(); + _host = deviceConfig["output"].toString("127.0.0.1").toStdString(); + _port = deviceConfig["port"].toInt(4223); + _uid = deviceConfig["uid"].toString().toStdString(); + _interval = deviceConfig["rate"].toInt(); if ((unsigned)_ledCount > MAX_NUM_LEDS) { @@ -55,7 +55,7 @@ bool LedDeviceTinkerforge::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceTinkerforge::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceTinkerforge::construct(const QJsonObject &deviceConfig) { return new LedDeviceTinkerforge(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceTinkerforge.h b/libsrc/leddevice/LedDeviceTinkerforge.h index d3e3bd2f..d282c14b 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.h +++ b/libsrc/leddevice/LedDeviceTinkerforge.h @@ -20,7 +20,7 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceTinkerforge(const Json::Value &deviceConfig); + LedDeviceTinkerforge(const QJsonObject &deviceConfig); virtual ~LedDeviceTinkerforge(); @@ -29,10 +29,10 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Attempts to open a connection to the master bricklet and the led strip bricklet. diff --git a/libsrc/leddevice/LedDeviceTpm2.cpp b/libsrc/leddevice/LedDeviceTpm2.cpp index cd2b8483..abf6012c 100644 --- a/libsrc/leddevice/LedDeviceTpm2.cpp +++ b/libsrc/leddevice/LedDeviceTpm2.cpp @@ -1,18 +1,18 @@ #include "LedDeviceTpm2.h" -LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig) +LedDeviceTpm2::LedDeviceTpm2(const QJsonObject &deviceConfig) : ProviderRs232() { _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceTpm2::construct(const QJsonObject &deviceConfig) { return new LedDeviceTpm2(deviceConfig); } -bool LedDeviceTpm2::init(const Json::Value &deviceConfig) +bool LedDeviceTpm2::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceTpm2.h b/libsrc/leddevice/LedDeviceTpm2.h index eb810c13..11b923c2 100644 --- a/libsrc/leddevice/LedDeviceTpm2.h +++ b/libsrc/leddevice/LedDeviceTpm2.h @@ -14,12 +14,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceTpm2(const Json::Value &deviceConfig); + LedDeviceTpm2(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceTpm2net.cpp b/libsrc/leddevice/LedDeviceTpm2net.cpp index cb422fb1..56e9f86c 100644 --- a/libsrc/leddevice/LedDeviceTpm2net.cpp +++ b/libsrc/leddevice/LedDeviceTpm2net.cpp @@ -1,24 +1,24 @@ #include "LedDeviceTpm2net.h" -LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig) +LedDeviceTpm2net::LedDeviceTpm2net(const QJsonObject &deviceConfig) : ProviderUdp() { _deviceReady = init(deviceConfig); } -bool LedDeviceTpm2net::init(const Json::Value &deviceConfig) +bool LedDeviceTpm2net::init(const QJsonObject &deviceConfig) { _LatchTime_ns = 104000; _port = TPM2_DEFAULT_PORT; ProviderUdp::init(deviceConfig); - _tpm2_max = deviceConfig.get("max-packet", 170).asInt(); + _tpm2_max = deviceConfig["max-packet"].toInt(170); _tpm2ByteCount = 3 * _ledCount; _tpm2TotalPackets = 1 + _tpm2ByteCount / _tpm2_max; return true; } -LedDevice* LedDeviceTpm2net::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceTpm2net::construct(const QJsonObject &deviceConfig) { return new LedDeviceTpm2net(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceTpm2net.h b/libsrc/leddevice/LedDeviceTpm2net.h index 40baf2a5..308e3d7e 100644 --- a/libsrc/leddevice/LedDeviceTpm2net.h +++ b/libsrc/leddevice/LedDeviceTpm2net.h @@ -16,17 +16,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceTpm2net(const Json::Value &deviceConfig); + LedDeviceTpm2net(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceUdpE131.cpp b/libsrc/leddevice/LedDeviceUdpE131.cpp index 48589900..2df5a1e2 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.cpp +++ b/libsrc/leddevice/LedDeviceUdpE131.cpp @@ -4,20 +4,20 @@ // hyperion local includes #include "LedDeviceUdpE131.h" -LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig) +LedDeviceUdpE131::LedDeviceUdpE131(const QJsonObject &deviceConfig) : ProviderUdp() { _deviceReady = init(deviceConfig); } -bool LedDeviceUdpE131::init(const Json::Value &deviceConfig) +bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig) { _LatchTime_ns = 104000; _port = 5568; ProviderUdp::init(deviceConfig); - _e131_universe = deviceConfig.get("universe",1).asInt(); - _e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString(); - QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString()); + _e131_universe = deviceConfig["universe"].toInt(1); + _e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()).toStdString(); + QString _json_cid = deviceConfig["cid"].toString(""); if (_json_cid.isEmpty()) { @@ -31,7 +31,7 @@ bool LedDeviceUdpE131::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceUdpE131::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceUdpE131::construct(const QJsonObject &deviceConfig) { return new LedDeviceUdpE131(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceUdpE131.h b/libsrc/leddevice/LedDeviceUdpE131.h index b191b44b..fe5f63c3 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.h +++ b/libsrc/leddevice/LedDeviceUdpE131.h @@ -105,17 +105,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceUdpE131(const Json::Value &deviceConfig); + LedDeviceUdpE131(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: diff --git a/libsrc/leddevice/LedDeviceUdpH801.cpp b/libsrc/leddevice/LedDeviceUdpH801.cpp index d20c5b4c..bd31ba3c 100644 --- a/libsrc/leddevice/LedDeviceUdpH801.cpp +++ b/libsrc/leddevice/LedDeviceUdpH801.cpp @@ -1,12 +1,12 @@ #include "LedDeviceUdpH801.h" -LedDeviceUdpH801::LedDeviceUdpH801(const Json::Value &deviceConfig) +LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig) : ProviderUdp() { _deviceReady = init(deviceConfig); } -bool LedDeviceUdpH801::init(const Json::Value &deviceConfig) +bool LedDeviceUdpH801::init(const QJsonObject &deviceConfig) { /* The H801 port is fixed */ _LatchTime_ns = 10000000; @@ -14,9 +14,10 @@ bool LedDeviceUdpH801::init(const Json::Value &deviceConfig) ProviderUdp::init(deviceConfig, "255.255.255.255"); _ids.clear(); - for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) + QJsonArray lArray = deviceConfig["lightIds"].toArray(); + for (int i = 0; i < lArray.size(); i++) { - QString id(deviceConfig["lightIds"][i].asCString()); + QString id = lArray[i].toString(); _ids.push_back(id.toInt(nullptr, 16)); } @@ -35,7 +36,7 @@ bool LedDeviceUdpH801::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceUdpH801::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceUdpH801::construct(const QJsonObject &deviceConfig) { return new LedDeviceUdpH801(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceUdpH801.h b/libsrc/leddevice/LedDeviceUdpH801.h index 44d62c06..c698a6ca 100644 --- a/libsrc/leddevice/LedDeviceUdpH801.h +++ b/libsrc/leddevice/LedDeviceUdpH801.h @@ -22,17 +22,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceUdpH801(const Json::Value &deviceConfig); + LedDeviceUdpH801(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceUdpRaw.cpp b/libsrc/leddevice/LedDeviceUdpRaw.cpp index 41ffe9de..77adc0f4 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.cpp +++ b/libsrc/leddevice/LedDeviceUdpRaw.cpp @@ -1,6 +1,6 @@ #include "LedDeviceUdpRaw.h" -LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig) +LedDeviceUdpRaw::LedDeviceUdpRaw(const QJsonObject &deviceConfig) : ProviderUdp() { _LatchTime_ns = 500000; @@ -8,7 +8,7 @@ LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig) init(deviceConfig); } -LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceUdpRaw::construct(const QJsonObject &deviceConfig) { return new LedDeviceUdpRaw(deviceConfig); } diff --git a/libsrc/leddevice/LedDeviceUdpRaw.h b/libsrc/leddevice/LedDeviceUdpRaw.h index 8287879d..38071716 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.h +++ b/libsrc/leddevice/LedDeviceUdpRaw.h @@ -14,10 +14,10 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceUdpRaw(const Json::Value &deviceConfig); + LedDeviceUdpRaw(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceWS2812b.cpp b/libsrc/leddevice/LedDeviceWS2812b.cpp index 4fddb107..f80a7ccf 100644 --- a/libsrc/leddevice/LedDeviceWS2812b.cpp +++ b/libsrc/leddevice/LedDeviceWS2812b.cpp @@ -258,7 +258,7 @@ LedDeviceWS2812b::LedDeviceWS2812b() printf("WS2812b init finished \n"); } -LedDevice* LedDeviceWS2812b::construct(const Json::Value &) +LedDevice* LedDeviceWS2812b::construct(const QJsonObject &) { return new LedDeviceWS2812b(); } diff --git a/libsrc/leddevice/LedDeviceWS2812b.h b/libsrc/leddevice/LedDeviceWS2812b.h index 4efd6461..e763c92f 100644 --- a/libsrc/leddevice/LedDeviceWS2812b.h +++ b/libsrc/leddevice/LedDeviceWS2812b.h @@ -146,10 +146,10 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value&) {return true;}; + bool init(const QJsonObject&) {return true;}; /// constructs leddevice - static LedDevice* construct(const Json::Value &); + static LedDevice* construct(const QJsonObject &); private: /// diff --git a/libsrc/leddevice/LedDeviceWS281x.cpp b/libsrc/leddevice/LedDeviceWS281x.cpp index 447353b5..2e9ae0ca 100644 --- a/libsrc/leddevice/LedDeviceWS281x.cpp +++ b/libsrc/leddevice/LedDeviceWS281x.cpp @@ -2,7 +2,7 @@ #include "LedDeviceWS281x.h" -LedDeviceWS281x::LedDeviceWS281x(const Json::Value &deviceConfig) +LedDeviceWS281x::LedDeviceWS281x(const QJsonObject &deviceConfig) : LedDevice() { _deviceReady = init(deviceConfig); @@ -16,9 +16,9 @@ LedDeviceWS281x::~LedDeviceWS281x() } } -bool LedDeviceWS281x::init(const Json::Value &deviceConfig) +bool LedDeviceWS281x::init(const QJsonObject &deviceConfig) { - std::string whiteAlgorithm = deviceConfig.get("white_algorithm","white_off").asString(); + std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString(); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); if (_whiteAlgorithm == RGBW::INVALID) @@ -27,18 +27,18 @@ bool LedDeviceWS281x::init(const Json::Value &deviceConfig) return false; } - _channel = deviceConfig.get("pwmchannel", 0).asInt(); + _channel = deviceConfig["pwmchannel"].toInt(0); if (_channel != 0 && _channel != 1) { throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1."); } - _led_string.freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt(); - _led_string.dmanum = deviceConfig.get("dmanum", 5).asInt(); - _led_string.channel[_channel].gpionum = deviceConfig.get("gpio", 18).asInt(); - _led_string.channel[_channel].count = deviceConfig.get("leds", 256).asInt(); - _led_string.channel[_channel].invert = deviceConfig.get("invert", 0).asInt(); - _led_string.channel[_channel].strip_type = ((deviceConfig.get("rgbw", 0).asInt() == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB); + _led_string.freq = deviceConfig["freq"].toInt(800000ul); + _led_string.dmanum = deviceConfig["dmanum"].toInt(5); + _led_string.channel[_channel].gpionum = deviceConfig["gpio"].toInt(18); + _led_string.channel[_channel].count = deviceConfig["leds"].toInt(256); + _led_string.channel[_channel].invert = deviceConfig["invert"].toInt(0); + _led_string.channel[_channel].strip_type = ((deviceConfig["rgbw"].toInt(0) == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB); _led_string.channel[_channel].brightness = 255; _led_string.channel[!_channel].gpionum = 0; @@ -56,7 +56,7 @@ bool LedDeviceWS281x::init(const Json::Value &deviceConfig) return true; } -LedDevice* LedDeviceWS281x::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceWS281x::construct(const QJsonObject &deviceConfig) { return new LedDeviceWS281x(deviceConfig); } @@ -93,4 +93,3 @@ int LedDeviceWS281x::write(const std::vector &ledValues) return ws2811_render(&_led_string) ? -1 : 0; } - diff --git a/libsrc/leddevice/LedDeviceWS281x.h b/libsrc/leddevice/LedDeviceWS281x.h index 73a1cad1..27d3c27c 100644 --- a/libsrc/leddevice/LedDeviceWS281x.h +++ b/libsrc/leddevice/LedDeviceWS281x.h @@ -14,7 +14,7 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceWS281x(const Json::Value &deviceConfig); + LedDeviceWS281x(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice, waits for DMA to complete and then cleans up @@ -26,10 +26,10 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig); + bool init(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/LedDeviceWs2801.cpp b/libsrc/leddevice/LedDeviceWs2801.cpp index c9bc4233..b52cfc02 100644 --- a/libsrc/leddevice/LedDeviceWs2801.cpp +++ b/libsrc/leddevice/LedDeviceWs2801.cpp @@ -1,12 +1,12 @@ #include "LedDeviceWs2801.h" -LedDeviceWs2801::LedDeviceWs2801(const Json::Value &deviceConfig) +LedDeviceWs2801::LedDeviceWs2801(const QJsonObject &deviceConfig) : ProviderSpi() { _deviceReady = ProviderSpi::init(deviceConfig); } -LedDevice* LedDeviceWs2801::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceWs2801::construct(const QJsonObject &deviceConfig) { return new LedDeviceWs2801(deviceConfig); } @@ -18,4 +18,3 @@ int LedDeviceWs2801::write(const std::vector &ledValues) return writeBytes(dataLen, dataPtr); } - diff --git a/libsrc/leddevice/LedDeviceWs2801.h b/libsrc/leddevice/LedDeviceWs2801.h index c034d051..b405344e 100644 --- a/libsrc/leddevice/LedDeviceWs2801.h +++ b/libsrc/leddevice/LedDeviceWs2801.h @@ -13,10 +13,10 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceWs2801(const Json::Value &deviceConfig); + LedDeviceWs2801(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); protected: /// diff --git a/libsrc/leddevice/LedDeviceWs2812SPI.cpp b/libsrc/leddevice/LedDeviceWs2812SPI.cpp index 7a968c1f..39eafb5c 100644 --- a/libsrc/leddevice/LedDeviceWs2812SPI.cpp +++ b/libsrc/leddevice/LedDeviceWs2812SPI.cpp @@ -1,6 +1,6 @@ #include "LedDeviceWs2812SPI.h" -LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig) +LedDeviceWs2812SPI::LedDeviceWs2812SPI(const QJsonObject &deviceConfig) : ProviderSpi() , bitpair_to_byte { 0b10001000, @@ -12,12 +12,12 @@ LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig) _deviceReady = init(deviceConfig); } -LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig) +LedDevice* LedDeviceWs2812SPI::construct(const QJsonObject &deviceConfig) { return new LedDeviceWs2812SPI(deviceConfig); } -bool LedDeviceWs2812SPI::init(const Json::Value &deviceConfig) +bool LedDeviceWs2812SPI::init(const QJsonObject &deviceConfig) { _baudRate_Hz = 3000000; ProviderSpi::init(deviceConfig); diff --git a/libsrc/leddevice/LedDeviceWs2812SPI.h b/libsrc/leddevice/LedDeviceWs2812SPI.h index 186e6223..88dc3776 100644 --- a/libsrc/leddevice/LedDeviceWs2812SPI.h +++ b/libsrc/leddevice/LedDeviceWs2812SPI.h @@ -14,17 +14,17 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceWs2812SPI(const Json::Value &deviceConfig); + LedDeviceWs2812SPI(const QJsonObject &deviceConfig); /// constructs leddevice - static LedDevice* construct(const Json::Value &deviceConfig); + static LedDevice* construct(const QJsonObject &deviceConfig); /// /// Sets configuration /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); private: /// diff --git a/libsrc/leddevice/ProviderHID.cpp b/libsrc/leddevice/ProviderHID.cpp index f153a784..97b97781 100644 --- a/libsrc/leddevice/ProviderHID.cpp +++ b/libsrc/leddevice/ProviderHID.cpp @@ -27,11 +27,11 @@ ProviderHID::~ProviderHID() hid_exit(); } -bool ProviderHID::init(const Json::Value &deviceConfig) +bool ProviderHID::init(const QJsonObject &deviceConfig) { - _delayAfterConnect_ms = deviceConfig.get("delayAfterConnect", 0 ).asInt(); - auto VendorIdString = deviceConfig.get("VID", "0x2341").asString(); - auto ProductIdString = deviceConfig.get("PID", "0x8036").asString(); + _delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(0); + auto VendorIdString = deviceConfig["VID"].toString("0x2341").toStdString(); + auto ProductIdString = deviceConfig["PID"].toString("0x8036").toStdString(); // Convert HEX values to integer _VendorId = std::stoul(VendorIdString, nullptr, 16); diff --git a/libsrc/leddevice/ProviderHID.h b/libsrc/leddevice/ProviderHID.h index 3e1e4c40..d718462b 100644 --- a/libsrc/leddevice/ProviderHID.h +++ b/libsrc/leddevice/ProviderHID.h @@ -19,8 +19,6 @@ public: /// /// Constructs specific LedDevice /// - /// @param deviceConfig json device config - /// ProviderHID(); /// @@ -33,7 +31,7 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); /// /// Opens and configures the output device @@ -45,7 +43,7 @@ protected: /** * Writes the given bytes to the HID-device and * - * @param[in[ size The length of the data + * @param[in] size The length of the data * @param[in] data The data * * @return Zero on succes else negative diff --git a/libsrc/leddevice/ProviderRs232.cpp b/libsrc/leddevice/ProviderRs232.cpp index f0e849b9..8ffaff1f 100644 --- a/libsrc/leddevice/ProviderRs232.cpp +++ b/libsrc/leddevice/ProviderRs232.cpp @@ -32,13 +32,13 @@ ProviderRs232::ProviderRs232() connect(&_rs232Port, SIGNAL(readyRead()), this, SLOT(readyRead())); } -bool ProviderRs232::init(const Json::Value &deviceConfig) +bool ProviderRs232::init(const QJsonObject &deviceConfig) { closeDevice(); - _deviceName = deviceConfig["output"].asString(); - _baudRate_Hz = deviceConfig["rate"].asInt(); - _delayAfterConnect_ms = deviceConfig.get("delayAfterConnect",250).asInt(); - _timer.setInterval ( deviceConfig.get("rewriteTime",5000).asInt() ); + _deviceName = deviceConfig["output"].toString().toStdString(); + _baudRate_Hz = deviceConfig["rate"].toInt(); + _delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(250); + _timer.setInterval ( deviceConfig["rewriteTime"].toInt(5000) ); return true; } diff --git a/libsrc/leddevice/ProviderRs232.h b/libsrc/leddevice/ProviderRs232.h index 42a1c3a7..fe581b0c 100644 --- a/libsrc/leddevice/ProviderRs232.h +++ b/libsrc/leddevice/ProviderRs232.h @@ -25,7 +25,7 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open diff --git a/libsrc/leddevice/ProviderSpi.cpp b/libsrc/leddevice/ProviderSpi.cpp index 3768d5c8..2047c5ba 100644 --- a/libsrc/leddevice/ProviderSpi.cpp +++ b/libsrc/leddevice/ProviderSpi.cpp @@ -31,13 +31,13 @@ ProviderSpi::~ProviderSpi() // close(_fid); } -bool ProviderSpi::init(const Json::Value &deviceConfig) +bool ProviderSpi::init(const QJsonObject &deviceConfig) { - _deviceName = deviceConfig.get("output",_deviceName).asString(); - _baudRate_Hz = deviceConfig.get("rate",_baudRate_Hz).asInt(); - _latchTime_ns = deviceConfig.get("latchtime",_latchTime_ns).asInt(); - _spiMode = deviceConfig.get("spimode",_spiMode).asInt(); - _spiDataInvert = deviceConfig.get("invert",_spiDataInvert).asBool(); + _deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString(); + _baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz); + _latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns); + _spiMode = deviceConfig["spimode"].toInt(_spiMode); + _spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert); return true; } diff --git a/libsrc/leddevice/ProviderSpi.h b/libsrc/leddevice/ProviderSpi.h index 5fc0ca58..0d20cb4c 100644 --- a/libsrc/leddevice/ProviderSpi.h +++ b/libsrc/leddevice/ProviderSpi.h @@ -22,7 +22,7 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - virtual bool init(const Json::Value &deviceConfig); + virtual bool init(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open diff --git a/libsrc/leddevice/ProviderUdp.cpp b/libsrc/leddevice/ProviderUdp.cpp index dfb97b49..878821f1 100644 --- a/libsrc/leddevice/ProviderUdp.cpp +++ b/libsrc/leddevice/ProviderUdp.cpp @@ -28,28 +28,28 @@ ProviderUdp::~ProviderUdp() _udpSocket->close(); } -bool ProviderUdp::init(const Json::Value &deviceConfig, std::string defaultHost) +bool ProviderUdp::init(const QJsonObject &deviceConfig, std::string defaultHost) { - QString host = QString::fromStdString(deviceConfig.get("host",defaultHost).asString()); + QString host = deviceConfig["host"].toString(QString::fromStdString(defaultHost)); if (_address.setAddress(host) ) { - Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str()); + Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str()); } else { - Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str()); + Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str()); QHostInfo info = QHostInfo::fromName(host); if (info.addresses().isEmpty()) { - Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str()); + Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str()); throw std::runtime_error("invalid target address"); } - Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str()); + Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str()); _address = info.addresses().first(); } - _port = deviceConfig.get("port", _port).asUInt(); + _port = deviceConfig["port"].toInt(_port); if ( _port<=0 || _port > 65535) { throw std::runtime_error("invalid target port"); @@ -57,7 +57,7 @@ bool ProviderUdp::init(const Json::Value &deviceConfig, std::string defaultHost) Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port ); - _LatchTime_ns = deviceConfig.get("latchtime", _LatchTime_ns).asInt(); + _LatchTime_ns = deviceConfig["latchtime"].toInt(_LatchTime_ns); return true; } @@ -94,4 +94,3 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data) return retVal; } - diff --git a/libsrc/leddevice/ProviderUdp.h b/libsrc/leddevice/ProviderUdp.h index 6e7fa4b6..cd18c5c7 100644 --- a/libsrc/leddevice/ProviderUdp.h +++ b/libsrc/leddevice/ProviderUdp.h @@ -27,7 +27,7 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const Json::Value &deviceConfig, std::string defaultHost="127.0.0.1"); + bool init(const QJsonObject &deviceConfig, std::string defaultHost="127.0.0.1"); /// /// Opens and configures the output device @@ -56,4 +56,3 @@ protected: QHostAddress _address; quint16 _port; }; - diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index cd0a8762..4d821dc6 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -54,5 +54,4 @@ add_library(hyperion-utils qt5_use_modules(hyperion-utils Core) target_link_libraries(hyperion-utils - jsoncpp ${QT_LIBRARIES}) diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index c549d224..13dbc857 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -53,7 +53,7 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent) { loadConfig(configFile); - _hyperion = Hyperion::initInstance(_config, _qconfig, configFile.toStdString()); + _hyperion = Hyperion::initInstance(_qconfig, configFile.toStdString()); if (Logger::getLogLevel() == Logger::WARNING) @@ -162,24 +162,6 @@ void HyperionDaemon::loadConfig(const QString & configFile) QJsonSchemaChecker schemaChecker; schemaChecker.setSchema(schemaJson.object()); - // ----------------- DEPRECATED BEGIN ----------------- - // NOTE: Remove this code block when the conversion have been completed from JsonCpp to QTJson - - std::ifstream ifs(configFile.toStdString().c_str()); - - Json::Reader reader; - - if (! reader.parse(ifs, _config, false)) - { - // report to the user the failure and their locations in the document. - std::stringstream sstream; - sstream << "Failed to parse configuration: " << reader.getFormattedErrorMessages().c_str(); - - throw std::runtime_error(sstream.str()); - } - - // ----------------- DEPRECATED END ----------------- - _qconfig = QJsonFactory::readJson(configFile); if (!schemaChecker.validate(_qconfig)) { @@ -200,7 +182,7 @@ void HyperionDaemon::startInitialEffect() Hyperion *hyperion = Hyperion::getInstance(); // create boot sequence if the configuration is present - if (_config.isMember("initialEffect")) + if (_qconfig.contains("initialEffect")) { const QJsonObject & effectConfig = _qconfig["initialEffect"].toObject(); const int FG_PRIORITY = 0; diff --git a/src/hyperiond/hyperiond.h b/src/hyperiond/hyperiond.h index 8084a8d8..3ef3f8a1 100644 --- a/src/hyperiond/hyperiond.h +++ b/src/hyperiond/hyperiond.h @@ -40,15 +40,6 @@ #include - // ----------------- DEPRECATED BEGIN ----------------- - // NOTE: Remove this code block when the conversion have been completed from JsonCpp to QTJson - - #include - #include - #include - - // ----------------- DEPRECATED END ----------------- - #include #include #include @@ -81,7 +72,6 @@ private: void createGrabberX11(const QJsonObject & grabberConfig); Logger* _log; - Json::Value _config; // DEPRECATED | Remove this only when the conversion have been completed from JsonCpp to QTJson QJsonObject _qconfig; KODIVideoChecker* _kodiVideoChecker; JsonServer* _jsonServer; diff --git a/test/TestSpi.cpp b/test/TestSpi.cpp index c7e8de23..2b208045 100644 --- a/test/TestSpi.cpp +++ b/test/TestSpi.cpp @@ -9,11 +9,13 @@ // Local includes #include -#include + +//QT includes +#include #include "../libsrc/leddevice/LedDeviceWs2801.h" -Json::Value deviceConfig; +QJsonObject deviceConfig; void setColor(char* colorStr) @@ -147,7 +149,7 @@ int main(int argc, char** argv) return -1; } - deviceConfig["output"] = "/dev/spidev0.0"; + deviceConfig["output"] = QString("/dev/spidev0.0"); deviceConfig["rate"] = 40000; deviceConfig["latchtime"] = 500000; @@ -167,4 +169,3 @@ int main(int argc, char** argv) return 0; } -