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