1 /*
2 www.sourceforge.net/projects/tinyxpath
3 Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12 
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 
25 /**
26    \file action_store.cpp
27    \author Yves Berquin
28 */
29 
30 #include "action_store.h"
31 
32 #include <cstring>				// Added by neoneurone on 27th november, 2007
33 
34 namespace TinyXPath
35 {
36 
37 /// Allocation unit
38 const int i_alloc_size = 100;
39 
40 /// constructor
action_store()41 action_store::action_store ()
42 {
43    i_size = 0;
44    i_position = 0;
45    i_alloc = 0;
46    aipp_list = NULL;
47 }
48 
49 /// destructor
~action_store()50 action_store::~ action_store  ()
51 {
52    int i_item;
53 
54    if (i_size)
55    {
56       for (i_item = 0; i_item < i_size; i_item++)
57          delete aipp_list [i_item];
58       delete [] aipp_list;
59    }
60 }
61 
62 /// add an element on the placeholder, given its details
v_add(int i_1,int i_2,int i_3,const char * cp_string)63 void action_store::v_add (int i_1, int i_2, int i_3, const char * cp_string)
64 {
65    int i_new_size;
66    action_item ** aipp_new_list;
67 
68    if (i_size == i_alloc)
69    {
70       i_new_size = i_size + i_alloc_size;
71       aipp_new_list = new action_item * [i_new_size];
72       memset (aipp_new_list, 0, i_new_size * sizeof (action_item *));
73       if (i_size)
74       {
75          memcpy (aipp_new_list, aipp_list, i_size * sizeof (action_item *));
76          delete [] aipp_list;
77       }
78       aipp_list = aipp_new_list;
79       i_alloc = i_new_size;
80    }
81    aipp_list [i_size++] = new action_item (i_1, i_2, i_3, cp_string);
82 }
83 
84 /// Get one element from the placeholder
v_get(int i_entry,int & i_1,int & i_2,int & i_3,TIXML_STRING & S_out)85 void action_store::v_get (int i_entry, int & i_1, int & i_2, int & i_3, TIXML_STRING & S_out)
86 {
87    assert (i_entry >= 0 && i_entry < i_size);
88    assert (aipp_list [i_entry]);
89    aipp_list [i_entry] -> v_get (i_1, i_2, i_3, S_out);
90 }
91 
92 }
93