plptools
Loading...
Searching...
No Matches
deviceconfiguration.cc
Go to the documentation of this file.
1
/*
2
* This file is part of plptools.
3
*
4
* Copyright (c) 2026 Jason Morley <hello@jbmorley.co.uk>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* along with this program; if not, see <https://www.gnu.org/licenses/>.
18
*
19
*/
20
#include "config.h"
21
22
#include <string>
23
#include <unordered_map>
24
25
#include "
deviceconfiguration.h
"
26
27
#include "
ini.h
"
28
#include "
plpintl.h
"
29
#include "
uuid.h
"
30
31
std::unique_ptr<DeviceConfiguration>
DeviceConfiguration::deserialize
(
const
std::string &stringRepresentation) {
32
auto
contents =
ini::deserialize
(stringRepresentation);
33
if
(!contents) {
34
return
nullptr
;
35
}
36
if
(contents->find(
"id"
) == contents->end() || contents->find(
"name"
) == contents->end()) {
37
return
nullptr
;
38
}
39
return
std::unique_ptr<DeviceConfiguration>(
new
DeviceConfiguration
((*contents)[
"id"
], (*contents)[
"name"
]));
40
}
41
42
DeviceConfiguration::DeviceConfiguration
()
43
: id_(
uuid
::uuid4())
44
, name_(
_
(
"My Psion"
)) {
45
}
46
47
DeviceConfiguration::DeviceConfiguration
(std::string
const
&
id
, std::string
const
&name)
48
: id_(id)
49
, name_(name) {
50
}
51
52
std::string
DeviceConfiguration::serialize
()
const
{
53
return
ini::serialize
({
54
{
"id"
,
id_
},
55
{
"name"
,
name_
},
56
});
57
}
DeviceConfiguration::deserialize
static std::unique_ptr< DeviceConfiguration > deserialize(const std::string &contents)
Definition
deviceconfiguration.cc:31
DeviceConfiguration::DeviceConfiguration
DeviceConfiguration()
Definition
deviceconfiguration.cc:42
DeviceConfiguration::serialize
std::string serialize() const
Definition
deviceconfiguration.cc:52
DeviceConfiguration::name_
std::string name_
Definition
deviceconfiguration.h:59
DeviceConfiguration::id_
std::string id_
Definition
deviceconfiguration.h:58
deviceconfiguration.h
ini.h
ini::serialize
std::string serialize(const std::unordered_map< std::string, std::string > &contents)
Outputs simple flat ini data.
Definition
ini.cc:30
ini::deserialize
std::unique_ptr< std::unordered_map< std::string, std::string > > deserialize(const std::string contents)
Simple parser for flat ini data.
Definition
ini.cc:49
uuid
Definition
uuid.h:24
plpintl.h
_
#define _(String)
Definition
plpintl.h:34
uuid.h
lib
deviceconfiguration.cc
Generated by
1.12.0