VPersistence.cpp
Engine/source/Verve/Core/Persistence/VPersistence.cpp
Namespaces:
namespace
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#include "Verve/Core/Persistence/VPersistence.h" 25 26#include "Verve/Core/VController.h" 27#include "Verve/Core/VObject.h" 28 29namespace VPersistence 30{ 31 //----------------------------------------------------------------------------- 32 // 33 // VController 34 // 35 //----------------------------------------------------------------------------- 36 37 template <> 38 bool write( TiXmlElement *pElement, VController *pObject ) 39 { 40 // Write Properties. 41 if ( !writeProperties( pElement, pObject ) ) 42 { 43 return false; 44 } 45 46 // Write Data Table. 47 if ( !pObject->writeDataTable( pElement ) ) 48 { 49 return false; 50 } 51 52 // Write Objects. 53 return writeObjects( pElement, pObject ); 54 } 55 56 template <> 57 bool read( TiXmlElement *pElement, VController *pObject ) 58 { 59 // Read Properties. 60 if ( !readProperties( pElement, pObject ) ) 61 { 62 // Invalid Properties. 63 return false; 64 } 65 66 // Read Data Table. 67 if ( !pObject->readDataTable( pElement ) ) 68 { 69 // Invalid Data Table. 70 return false; 71 } 72 73 // Read Objects. 74 if ( !readObjects( pElement, pObject ) ) 75 { 76 // Invalid Read. 77 return false; 78 } 79 80 // Valid Read. 81 return true; 82 } 83 84 //----------------------------------------------------------------------------- 85 // 86 // VObject 87 // 88 //----------------------------------------------------------------------------- 89 90 template <> 91 bool write( TiXmlElement *pElement, VObject *pObject ) 92 { 93 // Create Element. 94 TiXmlElement *objectElement = new TiXmlElement( "VObject" ); 95 pElement->LinkEndChild( objectElement ); 96 97 // Attributes. 98 objectElement->SetAttribute( "Type", pObject->getClassName() ); 99 100 // Write Properties. 101 if ( !writeProperties( objectElement, pObject ) ) 102 { 103 return false; 104 } 105 106 // Write Objects. 107 return writeObjects( objectElement, pObject ); 108 } 109 110 template <> 111 bool read( TiXmlElement *pElement, VObject *pObject ) 112 { 113 // Read Properties. 114 if ( !readProperties( pElement, pObject ) ) 115 { 116 // Invalid Properties. 117 return false; 118 } 119 120 // Set Name Unique. 121 pObject->setLabelUnique( pObject->getLabel() ); 122 123 // Read Objects. 124 if ( !readObjects( pElement, pObject ) ) 125 { 126 // Invalid Objects. 127 return false; 128 } 129 130#ifdef VT_EDITOR 131 // Callback. 132 Con::executef( pObject, "onRead" ); 133#endif 134 135 // Valid Read. 136 return true; 137 } 138} 139