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 18 UserUsageConditions::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 38 UserUsageConditions::UserUsageConditions() 39 : 40 fCode(""), 41 fCopyMarkdown(""), 42 fMinimumAge(0) 43 { 44 } 45 46 47 UserUsageConditions::~UserUsageConditions() 48 { 49 } 50 51 52 const BString& 53 UserUsageConditions::Code() const 54 { 55 return fCode; 56 } 57 58 59 const uint8 60 UserUsageConditions::MinimumAge() const 61 { 62 return fMinimumAge; 63 } 64 65 66 const BString& 67 UserUsageConditions::CopyMarkdown() const 68 { 69 return fCopyMarkdown; 70 } 71 72 73 void 74 UserUsageConditions::SetCode(const BString& code) 75 { 76 fCode = code; 77 } 78 79 80 void 81 UserUsageConditions::SetMinimumAge(uint8 age) 82 { 83 fMinimumAge = age; 84 } 85 86 87 void 88 UserUsageConditions::SetCopyMarkdown(const BString& copyMarkdown) 89 { 90 fCopyMarkdown = copyMarkdown; 91 } 92 93 94 status_t 95 UserUsageConditions::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 }