Protocol++® (Protocolpp®)  v5.6.2
jarray Class Reference

#include "include/jarray.h"

Detailed Description

Array Class for Protocol++® (ProtocolPP®)

This is the array class used throughout ProtocolPP® (Protocol++®) and it's derivatives. It's main purpose is to provide easy accessibilty to data for the user. There are several different types of constuctor for the class

The standard constructor generates a empty array of size zero and can be constructed as

The second type of constructor creates an array of the size requested initialized to zero

jarray<uint8_t> array2(20);

The third type creates an array from an initialier list

jarray<uint8_t> array10 {0xAB, 0xCD, 0xEF, 0x01, 0x23};

The fourth type creates an array of the size requested intialized with the given value

jarray<uint16_t> array3(10, 0xFFAA);

The fifth type creates a copy of another array

jarray<uint16_t> array4(array3);

The sixth type creates an array from a standard vector

std::vector<uint32_t> vector1(10, 0xAABBCCDD);
jarray<uint32_t> array5(vector1, endian_t::BIG);

The seventh type creates an array from a raw uint8_t pointer

uint8_t* pointer1 = new uint8_t[10];
jarray<uint8_t> array6(pointer1, 10);

The last constructor allows the user to convert from one type to another such as changing a uint32_t array to a uint8_t array

jarray<uint32_t> wordarray1(2, 0xAABBCCDD);
jarray<uint8_t> array7(wordarray1, endian_t::LITTLE);
array7 = [DDCCBBAA_DDCCBBAA]

The next set of methods are accessor methods for the array as follows:

// return array size (number of elements)
uint32_t array1_size = array1.get_size()
// returns whether the array is empty
bool empty = array2.empty(); // returns false
// returns first n elements from this array as new array, removing elements from this array
jarray<uint16_t> newarray3 = array3.split(5);
newarray3 = [FFAAFFAA_FFAAFFAA
FFAA]
// extract elements starting at n for the next y elements
jarray<uint8_t> extract = array5.extract(1,2);
extract = [BBCC]
// push an element onto the end of the array
array6.push_back(0x00);
array6 = [00000000_00000000_000000]
// removed element from the end of the array
array6.pop_back();
array6.pop_back();
array6 = [00000000_00000000]
// resize the array
array6.resize(array6.size()+10);
array6 = [00000000_00000000_00000000_00000000
0000]
// append array6 on the end of array3
array3.append(array6);
array3 = [FFAAFFAA_FFAAFFAA_FFAA0000_00000000
00000000_00000000_00000000_0000]
// append initializer list on the end of array3
array3.append({0xFF, 0xBB, 0xEE, 0xDD});
array3 = [FFAAFFAA_FFAAFFAA_FFAA0000_00000000
00000000_00000000_00000000_0000FFBB
EEDD]
// insert new array into array3
jarray<uint8_t> array8(2,0xAA);
array3.insert(24,array8);
array3 = [FFAAFFAA_FFAAFFAA_FFAA0000_00000000
00000000_00000000_AAAA0000_00000000]
// update array3 with new array
jarray<uint8_t> array9(8,0xCC);
array3.update(24,array9);
array3 = [FFAAFFAA_FFAAFFAA_FFAA0000_00000000
00000000_00000000_CCCCCCCC_CCCCCCCC]
// erase the first four bytes
array3.erase(0,4);
array3 = [FFAAFFAA_FFAA0000_00000000_00000000
00000000_CCCCCCCC_CCCCCCCC]
// reverse the array
array3.reverse()
array3 = [CCCCCCCC_CCCCCCCC_00000000_00000000
00000000_0000AAFF_AAFFAAFF]
// return the raw pointer to the underlying array
uint32_t* wordptr = array5.get_ptr();
// return the raw pointer as a constant pointer
const uin32_t* constptr = array5.get_ptr();
// convert the array to a string representation with no formatting
std::string strarray = array3.to_string();
array3 = "CCCCCCCCCCCCCCCC0000000000000000000000000000AAFFAAFFAAFF";
// convert the array to a string representation 16-bytes wide with formatting
std::string strpretty = array3.to_string(true);
array3 = "[CCCCCCCC_CCCCCCCC_00000000_00000000
00000000_0000AAFF_AAFFAAFF]"
// compare two arrays of the same type for differences, annotate differences
arrayx.debug(arrayz);
AAAABBBB_CCCCDDDD_EEEEFFFF_00001111 AAAABBBB_CCCCDDDD_EEEEFFFF_00001111
22223333_44445555_66667777_88889999 22223333_44445555_66667777_FE889999 <-- MISMATCH
22223333_44445555_66667777_88889999 22223333_44445555_66667777_FE889999 <-- MISMATCH

Overloaded operators allow two arrays of the same length to be manipulated on a element-by-element basis

  • XOR
  • OR
  • AND
  • MULTIPLY
  • ADD

For examples for their use see below

jarray<uint8_t> arrayX1(4,0xAA);
jarray<uint8_t> arrayX2(4,0xCC);
arrayX1 ^= arrayX2;
arrayX1 = [66666666]
arrayX1 |= arrayX2;
arrayX1 = [EEEEEEEE]
arrayX1 &= arrayX2;
arrayX1 = [88888888]
arrayX1 *= arrayX2;
arrayX1 = [78787878]
arrayX1 += arrayX2;
arrayX1 = [16161616]

Access to individual elements can be accomplished with the overloaded square bracket as follows

// get single element
uint8_t element1 = array3[7];
element1 = 0xCC
// retrieve element as a constant value
const uint32_t element2 = array5[1];
element2 = 0xAABBCCDD

Obtain the format for this array (endian format) with

endian_t thisendian = array5.get_format();
endian_t
Definition: jenum.h:1210

For API Documentation:

See also
ProtocolPP::jarray

For Additional Documentation:

See also
jarray
Protocol++® (ProtocolPP®) written by : John Peter Greninger • © John Peter Greninger 2015-2024 • All Rights Reserved
All copyrights and trademarks are the property of their respective owners

The source code contained or described herein and all documents related to the source code (herein called "Material") are owned by John Peter Greninger and Sheila Rocha Greninger. Title to the Material remains with John Peter Greninger and Sheila Rocha Greninger. The Material contains trade secrets and proprietary and confidential information of John Peter Greninger and Sheila Rocha Greninger. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without prior express written consent of John Peter Greninger and Sheila Rocha Greninger (both are required)

No license under any patent, copyright, trade secret, or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel, or otherwise. Any license under such intellectual property rights must be express and approved by John Peter Greninger and Sheila Rocha Greninger in writing

Licensing information can be found at www.protocolpp.com/license with use of the binary forms permitted provided that the following conditions are met:

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution
  • Any and all modifications must be returned to John Peter Greninger at GitHub.com https://github.com/jpgreninger/protocolpp for evaluation. Inclusion of modifications in the source code shall be determined solely by John Peter Greninger. Failure to provide modifications shall render this license NULL and VOID and revoke any rights to use of Protocol++®
  • Commercial use (incidental or not) requires a fee-based license obtainable at www.protocolpp.com/shop
  • Academic or research use requires prior written and notarized permission from John Peter and Sheila Rocha Greninger

Use of the source code requires purchase of the source code. Source code can be purchased at www.protocolpp.com/shop

  • US Copyrights at https://www.copyright.gov/
    • TXu002059872 (Version 1.0.0)
    • TXu002066632 (Version 1.2.7)
    • TXu002082674 (Version 1.4.0)
    • TXu002097880 (Version 2.0.0)
    • TXu002169236 (Version 3.0.1)
    • TXu002182417 (Version 4.0.0)
    • TXu002219402 (Version 5.0.0)
    • TXu002272076 (Version 5.2.1)
    • TXu002383571 (Version 5.4.3)

The name of its contributor may not be used to endorse or promote products derived from this software without specific prior written permission and licensing

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE


The documentation for this class was generated from the following file: