File: mount.cpp

package info (click to toggle)
lensfun 0.3.95-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,812 kB
  • sloc: xml: 34,868; cpp: 10,776; python: 3,617; ansic: 587; sh: 70; makefile: 14; javascript: 3
file content (119 lines) | stat: -rw-r--r-- 2,126 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
    Private constructors and destructors
    Copyright (C) 2007 by Andrew Zabolotny
*/

#include "config.h"
#include "lensfun.h"
#include "lensfunprv.h"
#include <stdlib.h>

lfMount::lfMount ()
{
    Name = NULL;
    Compat = NULL;
}

lfMount::~lfMount ()
{
    lf_free (Name);
    for (char* m: MountCompat)
        free(m);
}

lfMount::lfMount (const lfMount &other)
{
    Name = lf_mlstr_dup (other.Name);
    Compat = NULL;

    MountCompat.clear();
    const char* const* otherMounts = other.GetCompats();
    for (int i = 0; otherMounts[i]; i++)
        AddCompat(otherMounts[i]);
}

lfMount &lfMount::operator = (const lfMount &other)
{
    lf_free (Name);
    Name = lf_mlstr_dup (other.Name);
    Compat = NULL;

    MountCompat.clear();
    const char* const* otherMounts = other.GetCompats();
    for (int i = 0; otherMounts[i]; i++)
        AddCompat(otherMounts[i]);

    return *this;
}

bool lfMount::operator == (const lfMount& other)
{
    return _lf_strcmp (Name, other.Name) == 0;
}

void lfMount::SetName (const char *val, const char *lang)
{
    Name = lf_mlstr_add (Name, lang, val);
}

void lfMount::AddCompat (const char *val)
{
    if (val)
    {
        char* p = (char*)malloc(strlen(val) + 1);
        strcpy(p, val);
        MountCompat.push_back(p);

        // add terminating NULL
        _lf_terminate_vec(MountCompat);

        // legacy compat pointer
        Compat = (char**)MountCompat.data();
    }
}

const char* const* lfMount::GetCompats() const
{
    return MountCompat.data();
}

bool lfMount::Check ()
{
    if (!Name)
        return false;

    return true;
}


//---------------------------// The C interface //---------------------------//

lfMount *lf_mount_new ()
{
    return new lfMount ();
}

lfMount *lf_mount_create ()
{
    return new lfMount ();
}

void lf_mount_destroy (lfMount *mount)
{
    delete mount;
}

cbool lf_mount_check (lfMount *mount)
{
    return mount->Check ();
}

void lf_mount_add_compat (lfMount *mount, const char *val)
{
    mount->AddCompat(val);
}

const char* const* lf_mount_get_compats (lfMount *mount)
{
    return mount->GetCompats();
}