1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2012-2014 - Scilab Enterprises - Calixte DENIZET 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 #ifndef __XMLNODELIST_HXX__ 17 #define __XMLNODELIST_HXX__ 18 19 #include "XMLList.hxx" 20 #include "dynlib_xml_scilab.h" 21 #include "xml.h" 22 23 namespace org_modules_xml 24 { 25 class XMLElement; 26 class XMLDocument; 27 28 /** 29 * @file 30 * @author Calixte DENIZET <calixte.denizet@scilab.org> 31 * 32 * Class to wrap the list of the children of a node 33 */ 34 class XML_SCILAB_IMPEXP XMLNodeList: public XMLList 35 { 36 37 const XMLDocument & doc; 38 xmlNode *parent; 39 int prev; 40 xmlNode *prevNode; 41 42 public: 43 /** 44 * Default constructor 45 * @param doc the XMLDocument where this nodelist is 46 * @param parent the parent node 47 */ 48 XMLNodeList(const XMLDocument & doc, xmlNode * parent); 49 50 ~XMLNodeList(); 51 52 void *getRealXMLPointer() const; 53 54 const char **getContentFromList() const; 55 56 const char **getNameFromList() const; 57 58 void remove() const; 59 60 /** 61 * Removes an element 62 * @param index the index of the element to remove 63 */ 64 void removeElementAtPosition(int index); 65 66 /** 67 * @anchor setElementAtPosition 68 * Sets an element at a given index. 69 * If the index is an integer, then according to the index value the element 70 * will be inserted at tail, or will replaced the existing one. 71 * If the index is not an integer, then the element will be inserted between the 72 * elements with indexes floor(index) and floor(index)+1. 73 * @param index the index 74 * @param elem the element to insert 75 */ 76 void setElementAtPosition(double index, const XMLElement & elem); 77 78 /** 79 * See @ref setElementAtPosition 80 * @param index the index 81 * @param document the document containing the root which will be inserted 82 */ 83 void setElementAtPosition(double index, const XMLDocument & document); 84 85 /** 86 * See @ref setElementAtPosition 87 * @param index the index 88 * @param xmlCode the XML code for the element which will be inserted 89 */ 90 void setElementAtPosition(double index, const std::string & xmlCode); 91 92 /** 93 * See @ref setElementAtPosition 94 * @param index the index 95 * @param list the list of the elements which will be inserted 96 */ 97 void setElementAtPosition(double index, const XMLNodeList & list); 98 99 /** 100 * Gets the parent node behind this children list. 101 * @return the parent node 102 */ getRealNode() const103 xmlNode *getRealNode() const 104 { 105 return parent->children; 106 } 107 108 void setAttributeValue(const char **prefix, const char **name, const char **value, int lsize) const; 109 void setAttributeValue(const char **name, const char **value, int lsize) const; 110 const XMLObject *getXMLObjectParent() const; 111 const std::string dump() const; 112 const XMLObject *getListElement(int index); 113 114 /** 115 * Revalidate size after an eventual alteration (such as an element removal) 116 */ 117 void revalidateSize(); 118 119 /** 120 * Gets the node list size 121 * @param node the xmlNode 122 * @return the size 123 */ 124 static int getNodeListSize(xmlNode * node); 125 protected: 126 /** 127 * Replaces an element at a given index 128 * @param index the index 129 * @param elem the new element 130 */ 131 void replaceAtIndex(int index, const XMLElement & elem); 132 133 /** 134 * Inserts an element at beginning 135 * @param elem the element to insert 136 */ 137 void insertAtEnd(const XMLElement & elem); 138 139 /** 140 * Inserts an element at end 141 * @param elem the element to insert 142 */ 143 void insertAtBeginning(const XMLElement & elem); 144 145 /** 146 * Inserts an element at a given index 147 * @param index the index 148 * @param elem the element to insert 149 */ 150 void insertAtIndex(int index, const XMLElement & elem); 151 152 private: 153 /** 154 * Gets a node at a given index 155 * @param index the index 156 * @return the correspionding node 157 */ 158 xmlNode *getListNode(int index); 159 160 }; 161 } 162 163 #endif 164