build result

This commit is contained in:
Henry Schimke
2023-04-23 11:23:56 -05:00
parent b4f99b3195
commit cb7050a5dd
4 changed files with 58 additions and 63 deletions

View File

@@ -1,6 +1,6 @@
use std::{any::Any, rc::Rc}; use std::{any::Any, rc::Rc};
use crate::{common::ECIStringBuilder, Exceptions}; use crate::{common::ECIStringBuilder, Exceptions, RXingResult};
use super::StructuredAppendInfo; use super::StructuredAppendInfo;
@@ -64,59 +64,6 @@ where
} }
} }
// DecoderResult(const DecoderResult &) = delete;
// DecoderResult& operator=(const DecoderResult &) = delete;
// }
// public:
// DecoderResult() = default;
// DecoderResult(Error error) : _error(std::move(error)) {}
// DecoderResult(Content&& bytes) : _content(std::move(bytes)) {}
// DecoderResult(DecoderResult&&) noexcept = default;
// DecoderResult& operator=(DecoderResult&&) noexcept = default;
// bool isValid(bool includeErrors = false) const
// {
// return includeErrors || (_content.symbology.code != 0 && !_error);
// }
// const Content& content() const & { return _content; }
// Content&& content() && { return std::move(_content); }
// to keep the unit tests happy for now:
// std::wstring text() const { return _content.utfW(); }
// std::string symbologyIdentifier() const { return _content.symbology.toString(false); }
// Simple macro to set up getter/setter methods that save lots of boilerplate.
// It sets up a standard 'const & () const', 2 setters for setting lvalues via
// copy and 2 for setting rvalues via move. They are provided each to work
// either on lvalues (normal 'void (...)') or on rvalues (returning '*this' as
// rvalue). The latter can be used to optionally initialize a temporary in a
// return statement, e.g.
// return DecoderResult(bytes, text).setEcLevel(level);
// #define ZX_PROPERTY(TYPE, GETTER, SETTER) \
// const TYPE& GETTER() const & { return _##GETTER; } \
// TYPE&& GETTER() && { return std::move(_##GETTER); } \
// void SETTER(const TYPE& v) & { _##GETTER = v; } \
// void SETTER(TYPE&& v) & { _##GETTER = std::move(v); } \
// DecoderResult&& SETTER(const TYPE& v) && { _##GETTER = v; return std::move(*this); } \
// DecoderResult&& SETTER(TYPE&& v) && { _##GETTER = std::move(v); return std::move(*this); }
// ZX_PROPERTY(std::string, ecLevel, setEcLevel)
// ZX_PROPERTY(int, lineCount, setLineCount)
// ZX_PROPERTY(int, versionNumber, setVersionNumber)
// ZX_PROPERTY(StructuredAppendInfo, structuredAppend, setStructuredAppend)
// ZX_PROPERTY(Error, error, setError)
// ZX_PROPERTY(bool, isMirrored, setIsMirrored)
// ZX_PROPERTY(bool, readerInit, setReaderInit)
// ZX_PROPERTY(std::shared_ptr<CustomData>, extra, setExtra)
// #undef ZX_PROPERTY
// };
impl<T> DecoderResult<T> impl<T> DecoderResult<T>
where where
T: Copy + Clone + Default + Eq + PartialEq, T: Copy + Clone + Default + Eq + PartialEq,

View File

@@ -21,7 +21,9 @@
// import java.nio.charset.Charset; // import java.nio.charset.Charset;
// import java.nio.charset.StandardCharsets; // import java.nio.charset.StandardCharsets;
use std::{collections::HashMap, fmt}; use std::{collections::HashMap, fmt::{self, Display}};
use crate::BarcodeFormat;
use super::{CharacterSet, Eci, StringUtils}; use super::{CharacterSet, Eci, StringUtils};
@@ -126,10 +128,10 @@ impl ECIStringBuilder {
/// Change the current encoding characterset, finding an eci to do so /// Change the current encoding characterset, finding an eci to do so
pub fn switch_encoding(&mut self, charset: CharacterSet) { pub fn switch_encoding(&mut self, charset: CharacterSet) {
//self.append_eci(Eci::from(charset)) //self.append_eci(Eci::from(charset))
if (false && !self.has_eci) { if false && !self.has_eci {
self.eci_positions.clear(); self.eci_positions.clear();
} }
if (false || !self.has_eci) if false || !self.has_eci
//{self.eci_positions.push_back({eci, Size(bytes)});} //{self.eci_positions.push_back({eci, Size(bytes)});}
{ {
self.append_eci(Eci::from(charset)) self.append_eci(Eci::from(charset))

View File

@@ -306,10 +306,15 @@ impl QrReader {
} }
if (decoderResult.isValid()) { if (decoderResult.isValid()) {
results.push(RXingResult::new( // results.push(RXingResult::new(
&decoderResult.content().to_string(), // &decoderResult.content().to_string(),
decoderResult.content().bytes().to_vec(), // decoderResult.content().bytes().to_vec(),
position.to_vec(), // position.to_vec(),
// BarcodeFormat::QR_CODE,
// ));
results.push(RXingResult::with_decoder_result(
decoderResult,
position,
BarcodeFormat::QR_CODE, BarcodeFormat::QR_CODE,
)); ));
// results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::QR_CODE); // results.emplace_back(std::move(decoderResult), std::move(position), BarcodeFormat::QR_CODE);

View File

@@ -16,7 +16,10 @@
use std::{collections::HashMap, fmt}; use std::{collections::HashMap, fmt};
use crate::{BarcodeFormat, Point, RXingResultMetadataType, RXingResultMetadataValue}; use crate::{
common::cpp_essentials::DecoderResult, BarcodeFormat, MetadataDictionary, Point,
RXingResultMetadataType, RXingResultMetadataValue,
};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -95,6 +98,44 @@ impl RXingResult {
} }
} }
pub fn with_decoder_result<T>(
res: DecoderResult<T>,
resultPoints: &[Point],
format: BarcodeFormat,
) -> Self
where
T: Copy + Clone + Default + Eq + PartialEq,
{
let mut new_res = Self::new(
&res.text(),
res.content().bytes().to_vec(),
resultPoints.to_vec(),
format,
);
let mut meta_data = MetadataDictionary::new();
meta_data.insert(
RXingResultMetadataType::ERROR_CORRECTION_LEVEL,
RXingResultMetadataValue::ErrorCorrectionLevel(res.ecLevel().to_owned()),
);
meta_data.insert(
RXingResultMetadataType::STRUCTURED_APPEND_PARITY,
RXingResultMetadataValue::StructuredAppendParity(res.structuredAppend().count),
);
meta_data.insert(
RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE,
RXingResultMetadataValue::StructuredAppendSequence(res.structuredAppend().index),
);
meta_data.insert(
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER,
RXingResultMetadataValue::SymbologyIdentifier(res.symbologyIdentifier()),
);
new_res.putAllMetadata(meta_data);
new_res
}
/** /**
* @return raw text encoded by the barcode * @return raw text encoded by the barcode
*/ */