StringObj

 

package math;

public class StringObj {
 public String doc_out="";

 
 public StringObj(){}
}

const std::vector<std::string> StringFormatRandom::formatStrings = { "%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%", "%s%s%s%s", "%n%x%d", "%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%", "%0.0d", "%*$c", "%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%", "%d%d%d%d", "%r%s%-d%f%i", "%u%d%-i%x%b", "%c%o%-E%e%g%s", "%G%s%-d%r%u%f", }; StringFormatRandom::StringFormatRandom(std::shared_ptr<StringBase> obj, std::mt19937& rand) : StringMutator(obj, rand), randEngine(rand) {} std::int64_t StringFormatRandom::get_count() { return formatStrings.size(); } bool StringFormatRandom::supported(std::shared_ptr<StringBase> obj) { return (std::dynamic_pointer_cast<StringBase>(obj) != nullptr); } void StringFormatRandom::perform_mutation(std::shared_ptr<StringBase> obj, std::int64_t index) { if (index < formatStrings.size()) { obj->mutated_value = formatStrings[index]; } } int StringFormatRandom::get_cur_mutation_idx() { int index = cur_mutation_idx++; if (cur_mutation_idx >= static_cast<int>(formatStrings.size())) { cur_mutation_idx = 0; } return index; } void StringFormatRandom::sequential_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<StringBase>(obj); if (stringObj) { perform_mutation(stringObj, get_cur_mutation_idx()); stringObj->mutated = true; } } void StringFormatRandom::random_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<StringBase>(obj); if (stringObj) { // 生成随机索引 [0, size-1] std::uniform_int_distribution<size_t> dist(0, formatStrings.size() - 1); size_t randomIndex = dist(randEngine); perform_mutation(stringObj, randomIndex); stringObj->mutated = true; } }有没有什么问题
07-01
// // Created by k50048780 on 25-6-25. // #include "StringFormatRandom.h" #include "../../data_types/string_.h" #include <random> #include <algorithm> const std::vector<std::string> StringFormatRandom::formatStrings = { "%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%", "%s%s%s%s", "%n%x%d", "%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%", "%0.0d", "%*$c", "%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%", "%d%d%d%d", "%r%s%-d%f%i", "%u%d%-i%x%b", "%c%o%-E%e%g%s", "%G%s%-d%r%u%f", }; StringFormatRandom::StringFormatRandom(std::shared_ptr<StringBase> obj, std::mt19937& rand) : StringMutator(obj, rand), randEngine(rand) {} size_t StringFormatRandom::get_count() { return formatStrings.size(); } bool StringFormatRandom::supported(std::shared_ptr<StringBase> obj) { return (std::dynamic_pointer_cast<String>(obj) != nullptr); } void StringFormatRandom::perform_mutation(std::shared_ptr<String> obj, size_t index) { if (index < formatStrings.size()) { // 将选中的格式字符串作为新的变异值 obj->mutated_value = std::vector<uint8_t>(formatStrings[index].begin(), formatStrings[index].end()); } } void StringFormatRandom::sequential_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<String>(obj); if (stringObj) { perform_mutation(stringObj, get_current_mutation_index()); stringObj->mutated = true; } } void StringFormatRandom::random_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<String>(obj); if (stringObj) { // 生成随机索引 [0, size-1] std::uniform_int_distribution<size_t> dist(0, formatStrings.size() - 1); size_t randomIndex = dist(randEngine); perform_mutation(stringObj, randomIndex); stringObj->mutated = true; } } 下面是报错信息,如何修改?/data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.cpp:29:8: error: no declaration matches ‘size_t StringFormatRandom::get_count()’ 29 | size_t StringFormatRandom::get_count() { | ^~~~~~~~~~~~~~~~~~ In file included from /data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.cpp:5: /data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.h:17:18: note: candidate is: ‘virtual int64_t StringFormatRandom::get_count()’ 17 | std::int64_t get_count() override; | ^~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.h:14:7: note:class StringFormatRandom’ defined here 14 | class StringFormatRandom : public StringMutator { | ^~~~~~~~~~~~~~~~~~ /data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.cpp: In member function ‘virtual void StringFormatRandom::sequential_mutation(std::shared_ptr<StringBase>): /data/k50048780/cpp_mutator/mutators/string/StringFormatRandom.cpp:47:37: error: ‘get_current_mutation_index’ was not declared in this scope 47 | perform_mutation(stringObj, get_current_mutation_index()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ CMakeFiles/mutator.dir/build.make:398: recipe for target 'CMakeFiles/mutator.dir/mutators/string/StringFormatRandom.cpp.o' failed make[3]: *** [CMakeFiles/mutator.dir/mutators/string/StringFormatRandom.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mutator.dir/all' failed make[2]: *** [CMakeFiles/mutator.dir/all] Error 2 CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/mutator.dir/rule' failed make[1]: *** [CMakeFiles/mutator.dir/rule] Error 2 Makefile:118: recipe for target 'mutator' failed
06-28
// // Created by k50048780 on 25-6-25. // #include "StringFormatRandom.h" #include "../../data_types/string_.h" #include <random> #include <algorithm> const std::vector<std::string> StringFormatRandom::formatStrings = { "%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%", "%s%s%s%s", "%n%x%d", "%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%", "%0.0d", "%*$c", "%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%", "%d%d%d%d", "%r%s%-d%f%i", "%u%d%-i%x%b", "%c%o%-E%e%g%s", "%G%s%-d%r%u%f", }; StringFormatRandom::StringFormatRandom(std::shared_ptr<StringBase> obj, std::mt19937& rand) : StringMutator(obj, rand), randEngine(rand) {} std::int64_t StringFormatRandom::get_count() { return formatStrings.size(); } bool StringFormatRandom::supported(std::shared_ptr<StringBase> obj) { return (std::dynamic_pointer_cast<StringBase>(obj) != nullptr); } void StringFormatRandom::perform_mutation(std::shared_ptr<StringBase> obj, std::int64_t index) { if (index < formatStrings.size()) { obj->mutated_value = formatStrings[index]; } } int StringFormatRandom::get_cur_mutation_idx() { int index = cur_mutation_idx++; if (cur_mutation_idx >= static_cast<int>(formatStrings.size())) { cur_mutation_idx = 0; } return index; } void StringFormatRandom::sequential_mutation(std::shared_ptr<StringBase> obj) { perform_mutation(obj, get_cur_mutation_idx()); obj->mutated = true; } void StringFormatRandom::random_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<StringBase>(obj); if (stringObj) { // 生成随机索引 [0, size-1] std::uniform_int_distribution<size_t> dist(0, formatStrings.size() - 1); size_t randomIndex = dist(randEngine); perform_mutation(stringObj, randomIndex); stringObj->mutated = true; } }运行时打印变异结果,如何设置
07-01
# Copyright (c) Huawei Technologies Co., Ltd. 2012-2020. All rights reserved. from mutators.utils import StringMutator from data_types.string_ import String import base64 class StringFormatRandom(StringMutator): mutated_elements = [] values = ["%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%", "%s%s%s%s", "%n%x%d", "%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%", "%0.0d", "%*$c", "%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%", "%d%d%d%d", "%r%s%-d%f%i", "%u%d%-i%x%b", "%c%o%-E%e%g%s", "%G%s%-d%r%u%f", ] def __init__(self, obj, rand): super().__init__(obj, rand) self.encoding = obj.type @classmethod def supported(cls, obj): if isinstance(obj, String): return True return False def get_count(self): return len(self.values) def perform_mutation(self, obj, index): obj.mutated_value = self.values[index].encode(self.encoding) def sequential_mutation(self, obj): self.perform_mutation(obj, self.mutation_index) obj.mutated = True def random_mutation(self, obj): self.perform_mutation(obj, self.rand.randint(0, len(self.values) - 1)) obj.mutated = True 这个python版本转化为cpp版本如下,有什么问题??? #include "StringFormatRandom.h" #include "../../data_types/string_.h" #include <random> #include <algorithm> const std::vector<std::string> StringFormatRandom::formatStrings = { "%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%+i%@%s%-lc%d%#f%a%", "%s%s%s%s", "%n%x%d", "%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%&*()\t\r\n-=%s%d%u%x!@#$%", "%0.0d", "%*$c", "%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%", "%d%d%d%d", "%r%s%-d%f%i", "%u%d%-i%x%b", "%c%o%-E%e%g%s", "%G%s%-d%r%u%f", }; StringFormatRandom::StringFormatRandom(std::shared_ptr<StringBase> obj, std::mt19937& rand) : StringMutator(obj, rand), randEngine(rand) {} std::int64_t StringFormatRandom::get_count() { return formatStrings.size(); } bool StringFormatRandom::supported(std::shared_ptr<StringBase> obj) { return (std::dynamic_pointer_cast<StringBase>(obj) != nullptr); } void StringFormatRandom::perform_mutation(std::shared_ptr<StringBase> obj, std::int64_t index) { if (index >= formatStrings.size()){ return; }else { obj->mutated_value = formatStrings[index]; } } size_t StringFormatRandom::get_cur_idx() { size_t index = cur_idx++; if (cur_idx >= static_cast<int>(formatStrings.size())) { cur_idx = 0; } return index; } void StringFormatRandom::sequential_mutation(std::shared_ptr<StringBase> obj) { perform_mutation(obj, get_cur_idx()); obj->mutated = true; } void StringFormatRandom::random_mutation(std::shared_ptr<StringBase> obj) { auto stringObj = std::dynamic_pointer_cast<StringBase>(obj); if (stringObj) { std::uniform_int_distribution<size_t> dist(0, formatStrings.size() - 1); size_t randomIndex = dist(randEngine); perform_mutation(stringObj, randomIndex); stringObj->mutated = true; } } 头文件 #ifndef MUTATOR_STRINGFORMATRANDOM_H #define MUTATOR_STRINGFORMATRANDOM_H #include "../../utils/sample_util.h" #include "../../data_types/string_.h" #include <memory> #include <vector> #include <string> #include <random> class StringFormatRandom : public StringMutator { public: StringFormatRandom(std::shared_ptr<StringBase> obj, std::mt19937& rand); std::int64_t get_count() override; void sequential_mutation(std::shared_ptr<StringBase> obj) override; void random_mutation(std::shared_ptr<StringBase> obj) override; bool supported(std::shared_ptr<StringBase> obj) override; size_t get_cur_idx(); void perform_mutation(std::shared_ptr<StringBase> obj, std::int64_t index) override; static const std::vector<std::string> formatStrings; std::mt19937& randEngine; int cur_idx = 0; }; #endif //MUTATOR_STRINGFORMATRANDOM_H
07-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值