1    package org.apache.poi.hssf.record.formula;
2    import org.apache.poi.util.LittleEndian;
3    
4    /**
5     *
6     * @author Jason Height (jheight at chariot dot net dot au)
7     */
8    public class FuncVarPtg extends AbstractFunctionPtg{
9        
10       public final static byte sid  = 0x22;
11       
12       private FuncVarPtg() {
13         //Required for clone methods
14       }
15   
16    /**Creates new function pointer from a byte array 
17        * usually called while reading an excel file. 
18        */
19       public FuncVarPtg(byte[] data, int offset) {
20           offset++;
21           field_1_num_args = data[ offset + 0 ];
22           field_2_fnc_index  = LittleEndian.getShort(data,offset + 1 );
23       }
24       
25       /**
26        * Create a function ptg from a string tokenised by the parser
27        */
28       public FuncVarPtg(String pName, byte pNumOperands) {
29           field_1_num_args = pNumOperands;
30           field_2_fnc_index = lookupIndex(pName);
31           try{
32               returnClass = ( (Byte) functionData[field_2_fnc_index][0]).byteValue();
33               paramClass = (byte[]) functionData[field_2_fnc_index][1];
34           } catch (NullPointerException npe ) {
35               returnClass = Ptg.CLASS_VALUE;
36               paramClass = new byte[] {Ptg.CLASS_VALUE};
37           }
38       }
39       
40        public void writeBytes(byte[] array, int offset) {
41           array[offset+0]=(byte) (sid + ptgClass);
42           array[offset+1]=field_1_num_args;
43           LittleEndian.putShort(array,offset+2,field_2_fnc_index);
44       }
45       
46        public int getNumberOfOperands() {
47           return field_1_num_args;
48       }
49       
50       public Object clone() {
51         FuncVarPtg ptg = new FuncVarPtg();
52         ptg.field_1_num_args = field_1_num_args;
53         ptg.field_2_fnc_index = field_2_fnc_index;
54         return ptg;
55       }
56   
57       
58   }
59