Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some #344

Merged
merged 3 commits into from
Jan 16, 2025
Merged

fix some #344

merged 3 commits into from
Jan 16, 2025

Conversation

qicosmos
Copy link
Owner

@qicosmos
Copy link
Owner Author

qicosmos commented Jan 14, 2025

Hi @miyanyan
type_string的修改似乎有点问题,在windows下ci 测试没有通过:
pr:290fde8
测试:https://github.com/qicosmos/iguana/actions/runs/12759949381/job/35564555323?pr=344
看下是不是windows下的处理有点问题?

@miyanyan
Copy link

以test_xml的simple test为例,生成的xml如下

<struct Contents><Key>key</Key><LastModified>ddd</LastModified><ETag>ccc</ETag><Type>aaa</Type><Size>123</Size><StorageClass>aaa</StorageClass><Owner><ID>bbb</ID><DisplayName>sss</DisplayName></Owner></struct Contents>

标签里应该是不能加空格的吧,那么诸如struct AAA const AAA AAA &&这种type_string带空格的输出应该是都不允许的了

@miyanyan
Copy link

有的类的type_string输出带尖括号,xml标签里应该也是不允许的

@qicosmos
Copy link
Owner Author

之前测试是过的,看一下怎么适配一下msvc

@miyanyan
Copy link

有的类的type_string输出带尖括号,xml标签里应该也是不允许的

比如我构造一个

template<class T>
struct Haha
{
  std::string msg;
};
YLT_REFL(Haha<Contents>, msg);

那么之前未修改时的clang

Haha<Contents> a = {"haha"};
std::string ss;
iguana::to_xml(a, ss);

形成的字符串就是,这也是不允许的

<Haha<Contents>><msg>haha</msg></Haha<Contents>>

也就是type_string无论修改与否,现有的测试都是不全面的,to_xml之类的写法也会存在问题。

关于如何修改:

  • 既然type_string输出针对不同的格式会产生不同的不合规字符,那么不从type_string下手
  • xml, yaml等等都有其规则,那么在进行iguana::to_xml``iguana::to_yaml等函数时对输入先进行一次修改,按照规则进行替换
    • 比如空格替换为下划线,尖括号替换为横杠

@qicosmos
Copy link
Owner Author

ok 我看一下

@qicosmos
Copy link
Owner Author

qicosmos commented Jan 15, 2025

我看了一下msvc下的主要问题是普通的struct/class/union/enum 等符号都会保留,我对msvc做一个适配,如果name存在空格并且空格之前的前缀不是const和volatile时,则把前缀去掉,其它情况不做任何处理。

这样就可以适配普通的非const 的class struct了,会把非const/volatile的struct/class等前缀符号去掉。你看下我的修改,看有没有问题。

https://www.godbolt.org/z/WW86o4xnb

iguana 序列化会先把cv符都去掉的,所以不会有const volatile前缀字符串。

对于模版类型来说产生的尖括号的问题可以后面再改进,理论上不直接支持模版类型,如果要支持则可以通过设置其别名的方式绕过。参考:#347

@miyanyan

@miyanyan
Copy link

没有问题,对普通类型应该是正常的

不过我看to_xml里有remove_cv和remove_ref,那么需不需要remove_pointer呢,clang的*是有空格的

template <bool pretty = false, typename Stream, typename T,
          std::enable_if_t<ylt_refletable_v<T>, int> = 0>
IGUANA_INLINE void to_xml(T &&t, Stream &s) {
  constexpr std::string_view root_name =
      ylt::reflection::get_struct_name<ylt::reflection::remove_cvref_t<T>>();
  render_head<pretty, 0>(s, root_name);
  render_xml_value<pretty, 0>(s, std::forward<T>(t), root_name);
}

@qicosmos
Copy link
Owner Author

不用管*,因为不支持裸指针。

@qicosmos qicosmos merged commit 0a782e4 into master Jan 16, 2025
19 checks passed
@qicosmos qicosmos deleted the fix_type_string branch January 16, 2025 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants