Happy new year
[yazpp-moved-to-github.git] / src / yaz-z-databases.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2012 Index Data and Mike Taylor
3  * See the file LICENSE for details.
4  */
5
6 #if HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 #include <string.h>
10
11 #include <yazpp/z-databases.h>
12
13 using namespace yazpp_1;
14
15 Yaz_Z_Databases::Yaz_Z_Databases()
16 {
17     nmem = nmem_create ();
18     m_num = 0;
19     m_list = 0;
20 }
21
22 Yaz_Z_Databases::~Yaz_Z_Databases()
23 {
24     nmem_destroy (nmem);
25 }
26
27 void Yaz_Z_Databases::set (int num, const char **db)
28 {
29     nmem_reset (nmem);
30  
31     m_list = (char **) nmem_malloc (nmem, num * sizeof(char*));
32     m_num = num;
33     for (int i = 0; i<num; i++)
34         m_list[i] = nmem_strdup (nmem, db[i] ? db[i] : "Default");
35 }
36
37 void Yaz_Z_Databases::get (NMEM n, int *num, char ***db)
38 {
39     *num = m_num;
40     *db = (char **) nmem_malloc (n, m_num * sizeof(char*));
41     for (int i = 0; i < m_num; i++)
42         (*db)[i] = nmem_strdup (n, m_list[i]);
43 }
44
45 void Yaz_Z_Databases::get (ODR o, int *num, char ***db)
46 {
47     get (o->mem, num, db);
48 }
49
50 int Yaz_Z_Databases::match (Yaz_Z_Databases &db)
51 {
52     if (db.m_num != m_num)
53         return 0;
54     for (int i = 0; i<m_num; i++)
55         if (strcmp (m_list[i], db.m_list[i]))
56             return 0;
57     return 1;
58 }
59
60 int Yaz_Z_Databases::match (int num, const char **db)
61 {
62     if (num != m_num)
63         return 0;
64     for (int i = 0; i<m_num; i++)
65         if (strcmp (m_list[i], db[i]))
66             return 0;
67     return 1;
68 }
69 /*
70  * Local variables:
71  * c-basic-offset: 4
72  * c-file-style: "Stroustrup"
73  * indent-tabs-mode: nil
74  * End:
75  * vim: shiftwidth=4 tabstop=8 expandtab
76  */
77