001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.util.struct; 006 007/** Known data types for raw struct dynamic fields (see StructFieldDescriptor). */ 008public enum StructFieldType { 009 /** bool. */ 010 kBool("bool", false, false, 1), 011 /** char. */ 012 kChar("char", false, false, 1), 013 /** int8. */ 014 kInt8("int8", true, false, 1), 015 /** int16. */ 016 kInt16("int16", true, false, 2), 017 /** int32. */ 018 kInt32("int32", true, false, 4), 019 /** int64. */ 020 kInt64("int64", true, false, 8), 021 /** uint8. */ 022 kUint8("uint8", false, true, 1), 023 /** uint16. */ 024 kUint16("uint16", false, true, 2), 025 /** uint32. */ 026 kUint32("uint32", false, true, 4), 027 /** uint64. */ 028 kUint64("uint64", false, true, 8), 029 /** float. */ 030 kFloat("float", false, false, 4), 031 /** double. */ 032 kDouble("double", false, false, 8), 033 /** struct. */ 034 kStruct("struct", false, false, 0); 035 036 /** The name of the data type. */ 037 @SuppressWarnings("MemberName") 038 public final String name; 039 040 /** Indicates if the data type is a signed integer. */ 041 @SuppressWarnings("MemberName") 042 public final boolean isInt; 043 044 /** Indicates if the data type is an unsigned integer. */ 045 @SuppressWarnings("MemberName") 046 public final boolean isUint; 047 048 /** The size (in bytes) of the data type. */ 049 @SuppressWarnings("MemberName") 050 public final int size; 051 052 StructFieldType(String name, boolean isInt, boolean isUint, int size) { 053 this.name = name; 054 this.isInt = isInt; 055 this.isUint = isUint; 056 this.size = size; 057 } 058 059 @Override 060 public String toString() { 061 return name; 062 } 063 064 /** 065 * Get field type from string. 066 * 067 * @param str string 068 * @return field type 069 */ 070 public static StructFieldType fromString(String str) { 071 for (StructFieldType type : StructFieldType.values()) { 072 if (type.name.equals(str)) { 073 return type; 074 } 075 } 076 if ("float32".equals(str)) { 077 return kFloat; 078 } else if ("float64".equals(str)) { 079 return kDouble; 080 } else { 081 return kStruct; 082 } 083 } 084}