修复C++14兼容性问题& 逻辑检查

解决办法:特化类型的输出

cpp 复制代码
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <map>

// 模拟Alembic的V3f类型
struct MockV3f {
    float x, y, z;
    MockV3f(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
};

// 模拟Alembic的V2f类型
struct MockV2f {
    float x, y;
    MockV2f(float x_, float y_) : x(x_), y(y_) {}
};

// 模拟属性基类
class MockProperty {
protected:
    std::string name;
    
public:
    MockProperty(const std::string& propName) : name(propName) {}
    virtual ~MockProperty() = default;
    const std::string& getName() const { return name; }
    virtual void printValue() const = 0;
};

// 模拟标量属性
template<typename T>
class MockScalarProperty : public MockProperty {
private:
    T value;
    
public:
    MockScalarProperty(const std::string& propName, const T& val) 
        : MockProperty(propName), value(val) {}
    
    void set(const T& val) { value = val; }
    T get() const { return value; }
    
    void printValue() const override {
        std::cout << "  " << name << ": " << value << std::endl;
    }
};

// 特化bool类型的输出
template<>
void MockScalarProperty<bool>::printValue() const {
    std::cout << "  " << name << ": " << (value ? "true" : "false") << std::endl;
}

// 模拟数组属性
template<typename T>
class MockArrayProperty : public MockProperty {
private:
    std::vector<T> values;
    
public:
    MockArrayProperty(const std::string& propName) : MockProperty(propName) {}
    
    void set(const std::vector<T>& vals) { values = vals; }
    const std::vector<T>& get() const { return values; }
    
    void printValue() const override {
        std::cout << "  " << name << " (" << values.size() << " 个元素):" << std::endl;
        for (size_t i = 0; i < values.size(); ++i) {
            std::cout << "    [" << i << "]: " << values[i] << std::endl;
        }
    }
};

// 特化V3f类型的输出
template<>
void MockArrayProperty<MockV3f>::printValue() const {
    std::cout << "  " << name << " (" << values.size() << " 个元素):" << std::endl;
    for (size_t i = 0; i < values.size(); ++i) {
        std::cout << "    [" << i << "]: (" << values[i].x << ", " << values[i].y << ", " << values[i].z << ")" << std::endl;
    }
}

// 特化V2f类型的输出
template<>
void MockArrayProperty<MockV2f>::printValue() const {
    std::cout << "  " << name << " (" << values.size() << " 个元素):" << std::endl;
    for (size_t i = 0; i < values.size(); ++i) {
        std::cout << "    [" << i << "]: (" << values[i].x << ", " << values[i].y << ")" << std::endl;
    }
}

// 模拟复合属性
class MockCompoundProperty : public MockProperty {
private:
    std::map<std::string, std::unique_ptr<MockProperty>> properties;
    
public:
    MockCompoundProperty(const std::string& propName) : MockProperty(propName) {}
    
    template<typename T>
    void addScalarProperty(const std::string& name, const T& value) {
        properties[name] = std::make_unique<MockScalarProperty<T>>(name, value);
    }
    
    template<typename T>
    void addArrayProperty(const std::string& name, const std::vector<T>& values) {
        auto prop = std::make_unique<MockArrayProperty<T>>(name);
        prop->set(values);
        properties[name] = std::move(prop);
    }
    
    MockProperty* getProperty(const std::string& name) {
        auto it = properties.find(name);
        return it != properties.end() ? it->second.get() : nullptr;
    }
    
    void printValue() const override {
        std::cout << "  " << name << " (复合属性):" << std::endl;
        for (const auto& pair : properties) {
            pair.second->printValue();
        }
    }
};

int main() {
    try {
        std::cout << "=== Alembic 属性模拟测试 ===" << std::endl;
        
        // 创建复合属性容器
        MockCompoundProperty deskProps("desk_properties");
        
        // ==================== 写入标量属性 ====================
        std::cout << "\n1. 写入标量属性:" << std::endl;
        
        deskProps.addScalarProperty("desk_height", 0.75);
        std::cout << "  设置desk_height为: 0.75" << std::endl;
        
        deskProps.addScalarProperty("desk_width", 1.2);
        std::cout << "  设置desk_width为: 1.2" << std::endl;
        
        deskProps.addScalarProperty("material_name", std::string("Oak Wood"));
        std::cout << "  设置material_name为: Oak Wood" << std::endl;
        
        deskProps.addScalarProperty("is_movable", true);
        std::cout << "  设置is_movable为: true" << std::endl;
        
        // ==================== 写入数组属性 ====================
        std::cout << "\n2. 写入数组属性:" << std::endl;
        
        std::vector<MockV3f> vertices = {
            {0.0f, 0.0f, 0.0f}, {1.2f, 0.0f, 0.0f}, {1.2f, 0.0f, 0.6f}, {0.0f, 0.0f, 0.6f}
        };
        deskProps.addArrayProperty("desk_vertices", vertices);
        std::cout << "  写入" << vertices.size() << "个顶点位置" << std::endl;
        
        std::vector<MockV2f> uvs = {
            {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
        };
        deskProps.addArrayProperty("desk_uvs", uvs);
        std::cout << "  写入" << uvs.size() << "个UV坐标" << std::endl;
        
        // ==================== 读取属性 ====================
        std::cout << "\n--- 读取属性 ---" << std::endl;
        
        // 读取标量属性
        auto heightProp = dynamic_cast<MockScalarProperty<double>*>(deskProps.getProperty("desk_height"));
        if (heightProp) {
            std::cout << "  读取desk_height: " << heightProp->get() << std::endl;
        }
        
        auto widthProp = dynamic_cast<MockScalarProperty<double>*>(deskProps.getProperty("desk_width"));
        if (widthProp) {
            std::cout << "  读取desk_width: " << widthProp->get() << std::endl;
        }
        
        auto materialNameProp = dynamic_cast<MockScalarProperty<std::string>*>(deskProps.getProperty("material_name"));
        if (materialNameProp) {
            std::cout << "  读取material_name: " << materialNameProp->get() << std::endl;
        }
        
        auto movableProp = dynamic_cast<MockScalarProperty<bool>*>(deskProps.getProperty("is_movable"));
        if (movableProp) {
            std::cout << "  读取is_movable: " << (movableProp->get() ? "true" : "false") << std::endl;
        }
        
        // 读取数组属性
        auto verticesProp = dynamic_cast<MockArrayProperty<MockV3f>*>(deskProps.getProperty("desk_vertices"));
        if (verticesProp) {
            const auto& vertices_read = verticesProp->get();
            std::cout << "  读取" << vertices_read.size() << "个顶点位置:" << std::endl;
            for (size_t i = 0; i < vertices_read.size(); ++i) {
                const auto& vertex = vertices_read[i];
                std::cout << "    顶点" << i << ": (" << vertex.x << ", " << vertex.y << ", " << vertex.z << ")" << std::endl;
            }
        }
        
        auto uvsProp = dynamic_cast<MockArrayProperty<MockV2f>*>(deskProps.getProperty("desk_uvs"));
        if (uvsProp) {
            const auto& uvs_read = uvsProp->get();
            std::cout << "  读取" << uvs_read.size() << "个UV坐标:" << std::endl;
            for (size_t i = 0; i < uvs_read.size(); ++i) {
                const auto& uv = uvs_read[i];
                std::cout << "    UV" << i << ": (" << uv.x << ", " << uv.y << ")" << std::endl;
            }
        }
        
        // ==================== 显示所有属性 ====================
        std::cout << "\n--- 所有属性 ---" << std::endl;
        deskProps.printValue();
        
        // ==================== 总结 ====================
        std::cout << "\n=== 测试总结 ===" << std::endl;
        std::cout << "✓ 成功写入和读取标量属性 (double, string, bool)" << std::endl;
        std::cout << "✓ 成功写入和读取数组属性 (V3f, V2f)" << std::endl;
        std::cout << "✓ 模拟属性系统工作正常" << std::endl;
        std::cout << "\n注意:这是一个模拟版本,用于演示属性概念。" << std::endl;
        std::cout << "要使用真实的Alembic库,请安装依赖:sudo apt-get install libalembic-dev libhdf5-dev" << std::endl;
        
    } catch (const std::exception& e) {
        std::cerr << "错误: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}
相关推荐
辞旧 lekkk7 小时前
【Qt】信号和槽
linux·开发语言·数据库·qt·学习·mysql·萌新
2zcode8 小时前
运动模糊图像复原的MATLAB仿真与优化
开发语言·matlab
袁雅倩19978 小时前
当吸尘器、筋膜枪都用上Type-C,供电方案该怎么选?浅谈PD取电芯片ECP5702的应用
c语言·开发语言·支持向量机·动态规划·推荐算法·最小二乘法·图搜索算法
Aaswk9 小时前
Java Lambda 表达式与流处理
java·开发语言·python
万邦科技Lafite9 小时前
京东item_get接口实战案例:实时商品价格监控全流程解析
java·开发语言·数据库·python·开放api·淘宝开放平台
王老师青少年编程10 小时前
csp信奥赛C++高频考点专项训练之字符串 --【子串查找】:[NOIP 2009 提高组] 潜伏者
c++·字符串·csp·高频考点·信奥赛·子串查找·潜伏者
Cyber4K10 小时前
【Python专项】进阶语法-系统资源监控与数据采集(1)
开发语言·python·php
初願致夕霞10 小时前
基于系统调用的Linux网络编程——UDP与TCP
linux·网络·c++·tcp/ip·udp
Le_ee11 小时前
ctfweb:php/php短标签/.haccess+图片马/XXE
开发语言·前端·php
yong999011 小时前
MATLAB读取高光谱图像
开发语言·matlab