Kenji Arai / TYBLE16_mbedlized_os5_several_examples_1st

Dependencies:   nRF51_Vdd TextLCD BME280

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Text.h Source File

Text.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef NFC_COMMON_TEXT_H_
00018 #define NFC_COMMON_TEXT_H_
00019 
00020 #include <stdint.h>
00021 
00022 #include "platform/Span.h"
00023 
00024 #include "nfc/ndef/RecordParser.h"
00025 #include "nfc/ndef/MessageBuilder.h"
00026 
00027 namespace mbed {
00028 namespace nfc {
00029 namespace ndef {
00030 namespace common {
00031 
00032 /**
00033  * @addtogroup nfc
00034  * @{
00035  */
00036 
00037 /**
00038  * Represent the well known type text.
00039  */
00040 class Text {
00041 public:
00042     /**
00043      * Encoding of the text.
00044      */
00045     enum encoding_t {
00046         UTF8 = 0,//!< UTF8
00047         UTF16 = 1//!< UTF16
00048     };
00049 
00050     /**
00051      * Construct an empty text element.
00052      */
00053     Text();
00054 
00055     /**
00056      * Construct a text element from a data buffer and an encoding.
00057      *
00058      * @param text_encoding The encoding of the text.
00059      * @param language_code The string of the language code.
00060      * @param text The text buffer.
00061      *
00062      * @note To remove the NULL terminator of the C-string of the language_code
00063      * and text parameters, you can use the utility function span_from_cstr.
00064      */
00065     Text(
00066         encoding_t text_encoding,
00067         const Span<const uint8_t>  &language_code,
00068         const Span<const uint8_t>  &text
00069     );
00070 
00071     /**
00072      * Copy construct a text element.
00073      * @param to_copy
00074      */
00075     Text(const Text &to_copy);
00076 
00077     /**
00078      * Destroy a text element.
00079      */
00080     ~Text();
00081 
00082     /**
00083      * Copy assignment of another text element.
00084      * @param to_copy The Text instance to copy
00085      * @return a reference to this object.
00086      */
00087     Text &operator=(const Text &to_copy);
00088 
00089     /**
00090      * Copy a text from an external buffer.
00091      *
00092      * @param text_encoding The encoding of the text.
00093      * @param language_code The language code of the text.
00094      * @param text The text to copy.
00095      *
00096      * @note To remove the NULL terminator of the C-string of the language_code
00097      * and text parameters, you can use the utility function span_from_cstr.
00098      */
00099     void set_text(
00100         encoding_t text_encoding,
00101         const Span<const uint8_t>  &language_code,
00102         const Span<const uint8_t>  &text
00103     );
00104 
00105     /**
00106      * Get the encoding of the text.
00107      * @return The encoding of the text.
00108      */
00109     encoding_t get_encoding() const;
00110 
00111     /**
00112      * Return the language code.
00113      * @return The language code.
00114      */
00115     Span<const uint8_t>  get_language_code() const;
00116 
00117     /**
00118      * Return the text contained in this object.
00119      * @return The text contained in this object.
00120      */
00121     Span<const uint8_t>  get_text() const;
00122 
00123     /**
00124      * Append into a message builder
00125      */
00126     bool append_as_record(
00127         MessageBuilder &message_builder,
00128         bool is_last_record = false
00129     ) const;
00130 
00131     /**
00132      * Compute the size of this object in a ndef record.
00133      *
00134      * @return The size of the ndef record required to store this object.
00135      */
00136     size_t get_record_size() const;
00137 
00138 private:
00139     friend class TextParser;
00140 
00141     void move_data(uint8_t *text, size_t size);
00142 
00143     uint8_t *_text_record;
00144     size_t _text_record_size;
00145 };
00146 
00147 /**
00148  * Parse a Text.
00149  */
00150 class TextParser : public GenericRecordParser<TextParser, Text> {
00151 public:
00152     virtual bool do_parse(const Record &record, Text &text);
00153 };
00154 
00155 /**
00156  * @}
00157  */
00158 
00159 } // namespace common
00160 }  // namespace ndef
00161 } // namespace nfc
00162 } // namespace mbed
00163 
00164 
00165 #endif /* NFC_COMMON_TEXT_H_ */