1/*
2 * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6#include "UserUsageConditions.h"
7
8#include <stdio.h>
9
10// These are keys that are used to store this object's data into a BMessage
11// instance.
12
13#define KEY_COPY_MARKDOWN	"copyMarkdown"
14#define KEY_CODE			"code"
15#define KEY_MINIMUM_AGE		"minimumAge"
16
17
18UserUsageConditions::UserUsageConditions(BMessage* from)
19	:
20	fCode(""),
21	fCopyMarkdown(""),
22	fMinimumAge(0)
23{
24	int16 minimumAge;
25
26	if (from->FindInt16(KEY_MINIMUM_AGE, &minimumAge) != B_OK)
27		printf("expected key [%s] in the message data\n", KEY_MINIMUM_AGE);
28	fMinimumAge = (uint8) minimumAge;
29
30	if (from->FindString(KEY_CODE, &fCode) != B_OK)
31		printf("expected key [%s] in the message data\n", KEY_CODE);
32
33	if (from->FindString(KEY_COPY_MARKDOWN, &fCopyMarkdown) != B_OK)
34		printf("expected key [%s] in the message data\n", KEY_COPY_MARKDOWN);
35}
36
37
38UserUsageConditions::UserUsageConditions()
39	:
40	fCode(""),
41	fCopyMarkdown(""),
42	fMinimumAge(0)
43{
44}
45
46
47UserUsageConditions::~UserUsageConditions()
48{
49}
50
51
52const BString&
53UserUsageConditions::Code() const
54{
55	return fCode;
56}
57
58
59const uint8
60UserUsageConditions::MinimumAge() const
61{
62	return fMinimumAge;
63}
64
65
66const BString&
67UserUsageConditions::CopyMarkdown() const
68{
69	return fCopyMarkdown;
70}
71
72
73void
74UserUsageConditions::SetCode(const BString& code)
75{
76	fCode = code;
77}
78
79
80void
81UserUsageConditions::SetMinimumAge(uint8 age)
82{
83	fMinimumAge = age;
84}
85
86
87void
88UserUsageConditions::SetCopyMarkdown(const BString& copyMarkdown)
89{
90	fCopyMarkdown = copyMarkdown;
91}
92
93
94status_t
95UserUsageConditions::Archive(BMessage* into, bool deep) const
96{
97	into->AddInt16(KEY_MINIMUM_AGE, (int16) fMinimumAge);
98	into->AddString(KEY_CODE, fCode);
99	into->AddString(KEY_COPY_MARKDOWN, fCopyMarkdown);
100	return B_OK;
101}