//////////////////////////////////////////////////////////////////////// // Copyright (c) Nehmulos 2011-2014 // This file is part of N0 Strain Serialization Library. // // N0Strain-Serialization-Library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // N0Strain-Serialization-Library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with N0Strain-Serialization-Library. If not, see https://gnu.org/licenses/lgpl-3.0 //////////////////////////////////////////////////////////////////////// #ifndef POINTERCOLLECTOR_H_ #define POINTERCOLLECTOR_H_ #include "Describer.h" #include "DescribedObject.h" #include "N0SlibConstants.h" #include namespace nw { /// Used for the PointerCollector constructor namespace HandlePointers { enum HandlePointers { all, none, selected }; } // namespace HandlePointers struct N0PcArray { unsigned int size; unsigned int actualSize; unsigned int numberOfFoundPointersBeforeSearch; }; /// Collects pointers that are serialized in the serialize Function of an SerializedObject extern void collectPointers(DescribedObject* pointer); ///////////////////////////////////////////////////////////////////////////////////////////////////// /// This class runs through the serialize() function of a SerializedObject, /// but it doesn't write or read anything, it just grabs all pointers from /// serialize(SerializeObject*) and adds them to the static unhandeldPointers vector ///////////////////////////////////////////////////////////////////////////////////////////////////// class PointerCollector : public Describer { public: ///////////////////////////////////////////////////////////////////////////////////////////////////// /// The Constructor searches for pointers in the given pointer to add them to Serializer::unhandledPointers. /// The given pointer will be added. If the given pointer is null the constructor does nothing. /// PointerCollector calls the serialize function of the given pointer with this as Serializer. ///////////////////////////////////////////////////////////////////////////////////////////////////// PointerCollector(DescribedObject* pointer); /// PointerCollector does not save anything in it's instance, so there's nothing to remove for it. virtual ~PointerCollector(); void close(); ///< Does nothing void readFromFile(const String filename); ///< Does nothing bool isInWriteMode(); ///< Returns true, as this Class is required before writing bool isSilentCrawler(); ///< Returns true, this was written for pointercollector /// Return ture to make sure it's entered. bool conditionalPush(const String tagname, bool& condition); void describeArray(const String arrayName, const String elementsName, unsigned int size); ///< saves the arraySize void describeValueArray(const String arrayName, unsigned int size); bool enterNextElement(unsigned int iterator); ///< see skipOpenArrays /* Serialize functions */ void describeName(const String name); void describeValue(bool&); ///< Does nothing void describeValue(char&); ///< Does nothing void describeValue(unsigned char&); ///< Does nothing void describeValue(signed char&); ///< Does nothing void describeValue(short&); ///< Does nothing void describeValue(unsigned short&); ///< Does nothing void describeValue(int&); ///< Does nothing void describeValue(unsigned int&); ///< Does nothing void describeValue(long&); ///< Does nothing void describeValue(unsigned long&); ///< Does nothing void describeValue(float&); ///< Does nothing void describeValue(Pointer); ///< adds the pointer to unhandledPointers void describeValue(double&); ///< Does nothing void describeValue(long long&); ///< Does nothing void describeValue(long double&); ///< Does nothing void describeValue(String&); ///< Does nothing void describeBlob(const String childName,nw::Pointer binaryBlob, unsigned int blobSize); ///< Does nothing void comment(const String text); ///< Does nothing String getParentName(); ///< Does nothing void pop(); ///< Does nothing bool push(const String tagName); ///< Does nothing. Returns always true. ///////////////////////////////////////////////////////////////////////////////////////////////////// /// If it's true enterNextElement will return false if no pointers were found during the first loop. /// as we just use this class to crawl through the serialize function to search for pointers, /// we can skip arrays that don't contain pointers /// If this is a problem, you can set skipEmptyArrays to false; ///////////////////////////////////////////////////////////////////////////////////////////////////// static bool skipsEmptyArrays; private: std::stack openArrays; }; } // namespace nw #endif /* POINTERCOLLECTOR_H_ */