or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated

docs

index.md
tile.json

tessl/github-zxing-cpp--zxing-cpp

tessl install tessl/github-zxing-cpp--zxing-cpp@2.3.0

Open-source, multi-format linear/matrix barcode image processing library implemented in C++

utilities.mddocs/reference/

Utilities

ZXing-C++ provides utility functions for querying library version and supported barcode formats.

Version Information

// Get library version string
const std::string& Version();

Getting Version

#include "ZXing/ZXingCpp.h"

// Get version string
const std::string& version = ZXing::Version();
std::cout << "ZXing-C++ version: " << version << "\n";
// Output example: "2.3.0"

Version Format

The version string follows semantic versioning (MAJOR.MINOR.PATCH):

const std::string& version = ZXing::Version();

// Example: "2.3.0"
// MAJOR = 2 (breaking changes)
// MINOR = 3 (new features)
// PATCH = 0 (bug fixes)

Using Version for Compatibility

#include <sstream>

void checkVersion() {
    const std::string& version = ZXing::Version();

    // Parse version
    int major, minor, patch;
    char dot;
    std::istringstream iss(version);
    iss >> major >> dot >> minor >> dot >> patch;

    std::cout << "Version: " << major << "." << minor << "." << patch << "\n";

    // Check minimum version
    if (major < 2) {
        std::cerr << "Warning: Old ZXing version\n";
    }

    // Check for specific feature availability
    if (major >= 2 && minor >= 3) {
        std::cout << "New features available\n";
    }
}

Displaying in Application

void showAbout() {
    std::cout << "Application: MyApp v1.0\n";
    std::cout << "Barcode Engine: ZXing-C++ " << ZXing::Version() << "\n";
    std::cout << "License: Apache-2.0\n";
}

Supported Barcode Formats

#ifdef ZXING_EXPERIMENTAL_API
// Query supported formats for operations
BarcodeFormats SupportedBarcodeFormats(
    Operation op = Operation::CreateOrRead);

enum class Operation {
    Create,        // Write/create operation
    Read,          // Read/decode operation
    CreateAndRead, // Both create and read
    CreateOrRead   // Either create or read (union)
};
#endif

Checking Read Support

#ifdef ZXING_EXPERIMENTAL_API
#include "ZXing/ZXingCpp.h"

// Get all formats supported for reading
ZXing::BarcodeFormats readFormats =
    ZXing::SupportedBarcodeFormats(ZXing::Operation::Read);

std::cout << "Supported for reading:\n"
          << ZXing::ToString(readFormats) << "\n";

// Check if specific format is supported
if (readFormats & ZXing::BarcodeFormat::QRCode) {
    std::cout << "QR Code reading is supported\n";
}
#endif

Checking Write Support

#ifdef ZXING_EXPERIMENTAL_API
// Get all formats supported for writing
ZXing::BarcodeFormats writeFormats =
    ZXing::SupportedBarcodeFormats(ZXing::Operation::Create);

std::cout << "Supported for writing:\n"
          << ZXing::ToString(writeFormats) << "\n";

// Check if specific format is supported
if (writeFormats & ZXing::BarcodeFormat::DataMatrix) {
    std::cout << "Data Matrix writing is supported\n";
}
#endif

Checking Both Operations

#ifdef ZXING_EXPERIMENTAL_API
// Get formats supported for both reading AND writing
ZXing::BarcodeFormats bothFormats =
    ZXing::SupportedBarcodeFormats(ZXing::Operation::CreateAndRead);

std::cout << "Supported for both read and write:\n"
          << ZXing::ToString(bothFormats) << "\n";

// Get formats supported for reading OR writing
ZXing::BarcodeFormats anyFormats =
    ZXing::SupportedBarcodeFormats(ZXing::Operation::CreateOrRead);

std::cout << "Supported for read or write:\n"
          << ZXing::ToString(anyFormats) << "\n";
#endif

Runtime Feature Detection

#ifdef ZXING_EXPERIMENTAL_API
void selectFormat(bool needWrite) {
    ZXing::BarcodeFormats available;

    if (needWrite) {
        available = ZXing::SupportedBarcodeFormats(ZXing::Operation::CreateAndRead);
    } else {
        available = ZXing::SupportedBarcodeFormats(ZXing::Operation::Read);
    }

    // Prefer QR Code if available
    if (available & ZXing::BarcodeFormat::QRCode) {
        useFormat(ZXing::BarcodeFormat::QRCode);
    }
    // Fall back to Data Matrix
    else if (available & ZXing::BarcodeFormat::DataMatrix) {
        useFormat(ZXing::BarcodeFormat::DataMatrix);
    }
    // Fall back to any available format
    else {
        ZXing::BarcodeFormat first = /* extract first format from available */;
        useFormat(first);
    }
}
#endif

Build Configuration Detection

Checking Experimental API

#ifdef ZXING_EXPERIMENTAL_API
    std::cout << "Experimental API is enabled\n";
    std::cout << "Writing features available\n";
#else
    std::cout << "Only reading API is available\n";
#endif

Checking C++ Standard

#if __cplusplus >= 202002L
    std::cout << "C++20 or later\n";
#elif __cplusplus >= 201703L
    std::cout << "C++17 (some features limited)\n";
    std::cout << "DataBarLimited may not be supported\n";
#else
    std::cout << "Older C++ standard\n";
#endif

Feature Availability

Some features depend on C++ version:

void checkFeatures() {
    std::cout << "ZXing-C++ " << ZXing::Version() << "\n";

#if __cplusplus >= 202002L
    std::cout << "✓ Full feature set (C++20)\n";
    std::cout << "✓ DataBarLimited support\n";
    std::cout << "✓ Multi-symbol detection\n";
    std::cout << "✓ Position-independent DataMatrix\n";
#elif __cplusplus >= 201703L
    std::cout << "○ Basic features (C++17)\n";
    std::cout << "✗ DataBarLimited not supported\n";
    std::cout << "✗ Limited multi-symbol detection\n";
    std::cout << "✗ Limited DataMatrix detection\n";
#endif

#ifdef ZXING_EXPERIMENTAL_API
    std::cout << "✓ Experimental API enabled\n";
    std::cout << "✓ Writing/creation features\n";
#else
    std::cout << "✗ Experimental API disabled\n";
    std::cout << "✗ No writing features\n";
#endif
}

Complete System Information

#include "ZXing/ZXingCpp.h"
#include "ZXing/BarcodeFormat.h"

void printSystemInfo() {
    std::cout << "=== ZXing-C++ System Information ===\n\n";

    // Version
    std::cout << "Version: " << ZXing::Version() << "\n";

    // C++ standard
    std::cout << "C++ Standard: ";
#if __cplusplus >= 202002L
    std::cout << "C++20 or later\n";
#elif __cplusplus >= 201703L
    std::cout << "C++17\n";
#else
    std::cout << "C++14 or earlier\n";
#endif

    // API availability
    std::cout << "Experimental API: ";
#ifdef ZXING_EXPERIMENTAL_API
    std::cout << "Enabled\n";
#else
    std::cout << "Disabled\n";
#endif

    // Reading support
    std::cout << "\nReading Support:\n";
    std::cout << "All formats available for reading\n";

#ifdef ZXING_EXPERIMENTAL_API
    // Writing support
    std::cout << "\nWriting Support:\n";
    ZXing::BarcodeFormats writeFormats =
        ZXing::SupportedBarcodeFormats(ZXing::Operation::Create);
    std::cout << ZXing::ToString(writeFormats) << "\n";

    // Both operations
    std::cout << "\nFull Support (Read & Write):\n";
    ZXing::BarcodeFormats bothFormats =
        ZXing::SupportedBarcodeFormats(ZXing::Operation::CreateAndRead);
    std::cout << ZXing::ToString(bothFormats) << "\n";
#endif

    std::cout << "\n";
}

Format Listing

List All Formats

void listFormats() {
    std::cout << "Linear formats:\n";
    std::cout << ZXing::ToString(ZXing::BarcodeFormat::LinearCodes) << "\n";

    std::cout << "\n2D/Matrix formats:\n";
    std::cout << ZXing::ToString(ZXing::BarcodeFormat::MatrixCodes) << "\n";

    std::cout << "\nAll formats:\n";
    std::cout << ZXing::ToString(ZXing::BarcodeFormat::Any) << "\n";
}

Format Capabilities Table

void printFormatTable() {
    struct FormatInfo {
        ZXing::BarcodeFormat format;
        const char* name;
        const char* type;
        const char* features;
    };

    FormatInfo formats[] = {
        {ZXing::BarcodeFormat::QRCode, "QR Code", "2D",
         "High capacity, ECI, Structured Append"},
        {ZXing::BarcodeFormat::DataMatrix, "Data Matrix", "2D",
         "Compact, ECI, Structured Append"},
        {ZXing::BarcodeFormat::Aztec, "Aztec", "2D",
         "Compact, High error correction"},
        {ZXing::BarcodeFormat::PDF417, "PDF417", "Stacked",
         "High capacity, Structured Append"},
        {ZXing::BarcodeFormat::Code128, "Code 128", "Linear",
         "Full ASCII, Compact"},
        {ZXing::BarcodeFormat::EAN13, "EAN-13", "Linear",
         "Retail, Add-ons"},
        // ... more formats
    };

    std::cout << "Format            Type     Features\n";
    std::cout << "================================================\n";

    for (const auto& f : formats) {
        std::cout << std::left << std::setw(16) << f.name
                  << std::setw(8) << f.type
                  << f.features << "\n";
    }
}

Logging and Diagnostics

Diagnostic Information

void logDiagnostics() {
    std::cout << "ZXing-C++ Diagnostics\n";
    std::cout << "=====================\n";

    // Version
    std::cout << "Library Version: " << ZXing::Version() << "\n";

    // Compiler
#ifdef __GNUC__
    std::cout << "Compiler: GCC " << __GNUC__ << "." << __GNUC_MINOR__ << "\n";
#elif defined(_MSC_VER)
    std::cout << "Compiler: MSVC " << _MSC_VER << "\n";
#elif defined(__clang__)
    std::cout << "Compiler: Clang " << __clang_major__ << "."
              << __clang_minor__ << "\n";
#endif

    // Platform
#ifdef _WIN32
    std::cout << "Platform: Windows\n";
#elif defined(__APPLE__)
    std::cout << "Platform: macOS\n";
#elif defined(__linux__)
    std::cout << "Platform: Linux\n";
#else
    std::cout << "Platform: Unknown\n";
#endif

    // Architecture
#if defined(__x86_64__) || defined(_M_X64)
    std::cout << "Architecture: x64\n";
#elif defined(__i386__) || defined(_M_IX86)
    std::cout << "Architecture: x86\n";
#elif defined(__aarch64__) || defined(_M_ARM64)
    std::cout << "Architecture: ARM64\n";
#elif defined(__arm__) || defined(_M_ARM)
    std::cout << "Architecture: ARM32\n";
#endif

    // Build configuration
#ifdef NDEBUG
    std::cout << "Build: Release\n";
#else
    std::cout << "Build: Debug\n";
#endif
}

Performance Profiling Helpers

Timing Wrapper

#include <chrono>

template<typename Func>
void timeOperation(const char* name, Func&& func) {
    auto start = std::chrono::high_resolution_clock::now();

    func();

    auto end = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
        end - start);

    std::cout << name << " took " << duration.count() << " ms\n";
}

// Usage
timeOperation("Barcode Reading", [&]() {
    auto barcode = ZXing::ReadBarcode(image);
});

Thread Safety Information

void checkThreadSafety() {
    std::cout << "Thread Safety:\n";
    std::cout << "- ReadBarcode() is thread-safe\n";
    std::cout << "- ReadBarcodes() is thread-safe\n";
    std::cout << "- Multiple threads can read simultaneously\n";
    std::cout << "- ReaderOptions should not be shared without synchronization\n";

#ifdef ZXING_EXPERIMENTAL_API
    std::cout << "- CreateBarcodeFromText() is thread-safe\n";
    std::cout << "- CreateBarcodeFromBytes() is thread-safe\n";
    std::cout << "- WriteBarcodeToSVG() is thread-safe\n";
#endif
}

Best Practices

Version Checking

// Check version at startup
void initBarcodeLibrary() {
    const std::string& version = ZXing::Version();
    std::cout << "Initializing ZXing-C++ " << version << "\n";

    // Log to application logs
    LOG_INFO << "ZXing-C++ version: " << version;
}

Feature Detection

#ifdef ZXING_EXPERIMENTAL_API
// Use experimental features only when available
bool canWriteBarcodes() {
    ZXing::BarcodeFormats writeFormats =
        ZXing::SupportedBarcodeFormats(ZXing::Operation::Create);
    return writeFormats != ZXing::BarcodeFormat::None;
}
#else
bool canWriteBarcodes() {
    return false;
}
#endif

Graceful Degradation

void selectBestFormat(bool needWrite) {
#ifdef ZXING_EXPERIMENTAL_API
    if (needWrite) {
        auto formats = ZXing::SupportedBarcodeFormats(
            ZXing::Operation::CreateAndRead);

        if (formats & ZXing::BarcodeFormat::QRCode) {
            return ZXing::BarcodeFormat::QRCode;
        }
        // Fall through to other formats
    }
#endif

    // Reading always available
    return ZXing::BarcodeFormat::QRCode;
}

Related

  • Getting Started - Library overview and setup
  • Barcode Formats - All supported formats
  • Barcode Reading - Using the reading API
  • Barcode Writing - Using the writing API (experimental)