File: SHShared.cpp

package info (click to toggle)
yudit 2.5.4-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,528 kB
  • ctags: 8,403
  • sloc: cpp: 59,394; ansic: 2,585; perl: 2,398; makefile: 864; sh: 321
file content (94 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** 
 *  Yudit Unicode Editor Source File
 *
 *  GNU Copyright (C) 2002  Gaspar Sinai <gsinai@yudit.org>  
 *  GNU Copyright (C) 2001  Gaspar Sinai <gsinai@yudit.org>  
 *  GNU Copyright (C) 2000  Gaspar Sinai <gsinai@yudit.org>  
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, version 2,
 *  dated June 1991. See file COPYYING for details.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
#include "SHShared.h"
#include "SExcept.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/**
 * @author: Gaspar Sinai <gsinai@yudit.org>
 * @version: 2000-04-23
 */

static int debug_level = 0;

/**
 * Create a buffer that will be referenced by all vectors.
 * @param size is the minimum size on chars.
 */
SHShared::SHShared (unsigned int size)
{
  count=1; vectorSize=0;
  array = new char[size];
  CHECK_NEW(array);
  arraySize = size;
}

/**
 * Create a buffer that will be referenced by all vectors.
 * @param size is the minimum size on chars.
 * @param buffer - this will be copyes over one by one.
 */
SHShared::SHShared (const char* buffer, unsigned int size)
{
  count=1; array = 0;  arraySize=0; vectorSize=0;
  if (size==0)return;
  
  array = new char[size];
  CHECK_NEW(array);
  arraySize = size;
  //ensure (arraySize);
  memcpy (array, buffer, size);
}

/**
 * Create a new Object by copying an old one
 * @param a SHShared object to copy
 */
SHShared::SHShared (const SHShared& orig)
{
  count=1; array=0; arraySize=0; vectorSize=0;
  /* Copy */
  if (orig.arraySize!=0)
  {
  	ensure (orig.arraySize);
        /* This is needed this way becasue of Hashtable. Vectorsize in
           hashtabel does not mean continuous size  */
  	memcpy (array, orig.array, orig.arraySize);
  }
  vectorSize = orig.vectorSize;
}


/**
 * Sets debug printout levels
 */

int
SHShared::debug(int level)
{
  int prev = debug_level;
  debug_level = level;
  return prev;
}