Debian Codegraph @

libhylafax/CallID.c++

raw
1 /* $Id$ */
2 /*
3 * Copyright (c) 2004 iFAX Solutions, Inc.
4 * HylaFAX is a trademark of Silicon Graphics
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Sam Leffler and Silicon Graphics.
13 *
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 * OF THIS SOFTWARE.
24 */
25 #include "CallID.h"
26
27 const u_int CallID::NUMBER = 0;
28 const u_int CallID::NAME = 1;
29
30 CallID::CallID (int howmany)
31 : _id(howmany)
32 {
33 }
34
35 CallID::~CallID (void)
36 {
37 }
38
39 /*
40 * We need to manyally copy the array, becasue fxArray implementation doesn't
41 * do deep copy on the array, and we get double frees/corruption
42 */
43 void CallID::operator= (const CallID& a)
44 {
45 _id.resize(a._id.length());
46 for (u_int i = 0; i < _id.length(); i++)
47 _id[i] = a._id[i];
48 }
49
50 void CallID::resize(int i)
51 {
52 _id.resize(i);
53 }
54
55 size_t CallID::makeString(fxStr& output)
56 {
57 output.resize(0);
58 for (size_t i = 0; i < _id.length(); i++)
59 {
60 if (i)
61 output.append('\n');
62 output.append(_id[i]);
63 }
64 return _id.length();
65 }
66
67
68 const char* CallID::id (int i) const
69 {
70 fxAssert((u_int)i<_id.length(), "Invalid CallID[] index");
71 return _id[i];
72 }
73
74 int CallID::length (int i) const
75 {
76 fxAssert((u_int)i<_id.length(), "Invalid CallID[] index");
77 return _id[i].length();
78 }
79
80 fxStr& CallID::operator [](int i)
81 {
82 fxAssert((u_int)i<_id.length(), "Invalid CallID[] index");
83 return _id[i];
84 }
85
86 bool CallID::isEmpty (void) const
87 {
88 for (u_int i = 0; i < _id.length(); i++)
89 {
90 if (_id[i].length() != 0)
91 return false;
92 }
93 return true;
94 }
95 size_t CallID::size (void) const
96 {
97 return _id.length();
98 }