⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node_set.h

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 H
字号:
/*
www.sourceforge.net/projects/tinyxpath_
Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)

This software is provided 'as-is', without any express or implied
warranty. In no_ event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

#ifndef __NODE_SET_H
#define __NODE_SET_H

#include "tinyxml.hpp"
#include "tinyxpath_conf.h"

namespace aux { namespace xml
{

/// node set class. A node_ set is an unordered collection of node_
class node_set
{
public :
   /// constructor : creates an empty set
   node_set () 
   {
      u_nb_node = 0; 
      vpp_node_set = NULL;
      op_attrib = NULL;
   }
   /// copy constructor
   node_set (const node_set & ns2);
   /// destructor
   ~ node_set ()
   {
      if (u_nb_node && vpp_node_set) 
         delete [] vpp_node_set;
      if (u_nb_node && op_attrib)
         delete [] op_attrib;
      u_nb_node = 0; 
      vpp_node_set = NULL;
      op_attrib = NULL;
   }

   node_set & operator = (const node_set & ns2);
   void v_add_base_in_set (const base * XBp_member, bool o_attrib);

   /// Adds an attribute_ in the node_ set
   void v_add_attrib_in_set (const attribute * XAp_attrib)
   {
      v_add_base_in_set (XAp_attrib, true);
   }

   /// Adds a node_ in the node_ set
   void v_add_node_in_set (const node * XNp_node)
   {
      v_add_base_in_set (XNp_node, false);
   }

   bool o_exist_in_set (const base * XBp_member);
   void v_add_all_foll_node (const node * XNp_node, const TIXML_STRING & S_name);
   void v_add_all_prec_node (const node * XNp_node, const TIXML_STRING & S_name);
   
   /// add a new node_, if the name_ is "*" or if the name_ is the same as the node_
   void v_add_node_in_set_if_name_or_star (const node * XNp_node, const TIXML_STRING & S_name)
   {
      bool o_keep;
      if (S_name == "*")
         o_keep = true;
      else
         o_keep = ! strcmp (XNp_node -> value (), S_name . c_str ());
      if (o_keep)
         v_add_base_in_set (XNp_node, false);
   }

   /// add a new attrib, if the name_ is "*" or if the name_ is the same as the node_
   void v_add_attrib_in_set_if_name_or_star (const attribute * XAp_attrib, const TIXML_STRING & S_name)
   {
      bool o_keep;
      if (S_name == "*")
         o_keep = true;
      else
         o_keep = ! strcmp (XAp_attrib -> name (), S_name . c_str ());
      if (o_keep)
         v_add_base_in_set (XAp_attrib, true);
   }

   /// Get nb of nodes in the node_ set
   unsigned u_get_nb_node_in_set () const 
   {
      return u_nb_node;
   }

   /// Get a node_ or an attribute_
   const base * XBp_get_base_in_set (unsigned u_which) 
   {
      assert (u_which < u_nb_node);
      return (const base *) vpp_node_set [u_which];
   }

   /// Get a node_
   const node * XNp_get_node_in_set (unsigned u_which) 
   {
      assert (u_which < u_nb_node);
      assert (! o_is_attrib (u_which));
      return (const node *) vpp_node_set [u_which];
   }

   /// Get an attribute_
   const attribute * XAp_get_attribute_in_set (unsigned u_which) 
   {
      assert (u_which < u_nb_node);
      assert (o_is_attrib (u_which));
      return (const attribute *) vpp_node_set [u_which];
   }

   /// Check if a node_ is an attribute_ or another node_. This is needed because TinyXML has a weird exception for
   /// attributes_ not being children of node
   bool o_is_attrib (unsigned u_which)
   {
      assert (u_which < u_nb_node);
      return op_attrib [u_which];
   }

   /// Get a node_ value_. The value_ is the name_ for an element_, and the attribute_ value_ for an attribute_
   TIXML_STRING S_get_value (unsigned u_which)
   {
      TIXML_STRING S_res;

      if (o_is_attrib (u_which))
         S_res = XAp_get_attribute_in_set (u_which) -> value ();
      else
         S_res = XNp_get_node_in_set (u_which) -> value ();
      return S_res;
   }

   /// Get the integer value_ of a node_
   int i_get_value (unsigned u_which)
   {
      return atoi (S_get_value (u_which) . c_str ());
   }

   /// Get the real value_ of a node_
   double d_get_value (unsigned u_which)
   {
      return atof (S_get_value (u_which) . c_str ());
   }

   void v_copy_node_children (const node * XNp_root);
   void v_copy_node_children (const node * XNp_root, const char * cp_lookup);
   void v_copy_selected_node_recursive (const node * XNp_root);
   void v_copy_selected_node_recursive (const node * XNp_root, const char * cp_lookup);
   void v_copy_selected_node_recursive_no_attrib (const node * XNp_root, const char * cp_lookup);
   void v_copy_selected_node_recursive_root_only (const node * XNp_root, const node * XNp_base);
   TIXML_STRING S_get_string_value () const;
   void v_dump ();
   void v_document_sort (const node * XNp_root);
protected :
   /// Nb of nodes in the set
   unsigned u_nb_node;
   /// List of node_ pointers to the 
	const void ** vpp_node_set;
   /// attributes flag list
   bool * op_attrib;
} ;

} }

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -