private static int GetFieldSerializeLen(StringBuilder code, PropertyConfig field) { int flen = 0; Debug.WriteLine(field.Caption); CppTypeHelper.DoByCppType(field.Parent, field, (pro, len) => { flen = 4; }, (pro, type, len) => { if (len > 1) { flen = 4; } }, (pro, type, len) => { flen = 4; code.Append(" + " + GetEntitySerializeLen(type)); }, (pro, type, len) => { Debug.Assert(len < 1); }, (pro, type, len) => { Debug.Assert(len < 1); } ); return(flen); }
private static string WpfInputForm(ConfigBase config) { EntityConfig entityConfig = (EntityConfig)config; var code = new StringBuilder(); foreach (var field in entityConfig.LastProperties) { var typedef = CppTypeHelper.ToCppLastType(field.CppLastType) as TypedefItem; if (typedef != null && typedef.Items.Count > 0) { code.AppendFormat(@" <StackPanel VerticalAlignment=""Center"" Orientation =""Horizontal"" Width=""200px""> <TextBlock VerticalAlignment = ""Center"" Width =""80px"">{0}:</TextBlock> <ComboBox VerticalAlignment = ""Center"" Width =""120px"" SelectedValue = ""{{Binding Order.{1}}}"" ItemsSource = ""{{Binding {2}Dictionary}}"" DisplayMemberPath = ""name"" SelectedValuePath = ""value"" /> </StackPanel>", field.Caption, field.PropertyName, typedef.Name); } else { code.AppendFormat(@" <StackPanel VerticalAlignment=""Center"" Orientation =""Horizontal"" Width=""200px""> <TextBlock VerticalAlignment = ""Center"" Width =""80px"">{0}:</TextBlock> <TextBox VerticalAlignment = ""Center"" Width =""120px"" Text=""{{Binding Order.{1}}}""/> </StackPanel>", field.Caption, field.PropertyName); } } return(code.ToString()); }
private static void ToCppCoutCode(StringBuilder code, PropertyConfig field) { if (!string.IsNullOrWhiteSpace(field.Caption)) { code.AppendFormat(@" cout << ""{0}:", field.Caption); } else { code.AppendFormat(@" cout << ""{0}:", field.Name); } var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { code.AppendFormat(@""" << endl; print_screen(&value->{0});", field.Name); return; } var typedef = type as TypedefItem; if (typedef == null) { if (type.ToString() == "char") { code.AppendFormat(@""" << value->{0} << endl;", field.Name); } else if (field.Datalen > 0) { ArrayOut(code, field, field.Datalen.ToString()); } else { code.AppendFormat(@""" << value->{0} << endl;", field.Name); } return; } if (typedef.Items?.Count > 0) { EnumOut(code, field, typedef); } else if (typedef.KeyWork == "char") { code.AppendFormat(@""" << value->{0} << endl;", field.Name); } else if (field.Datalen > 0) { ArrayOut(code, field, field.Datalen.ToString()); } else if (string.IsNullOrWhiteSpace(typedef.ArrayLen)) { code.AppendFormat(@""" << value->{0} << endl;", field.Name); } else { ArrayOut(code, field, typedef.ArrayLen); } }
public static void GetCsRandomValue(StringBuilder code, PropertyConfig field, string entityName) { CppTypeHelper.DoByCppType(field.Parent, field, (pro, len) => { int len2 = (len - 1) / 2; var value = TestLine[random.Next(TestLine.Length - 1)]; if (value.Length > len2) { value = value.Substring(0, len2); } code.Append($@" //{field.Caption} {entityName}.{field.Name}=""{value}"";"); }, (pro, type, len) => { if (type == "tm") { code.Append($@" //{field.Caption} {entityName}.{field.Name} = DateTime.Now;"); } else if (len <= 0) { code.Append($@" //{field.Caption} {entityName}.{field.Name} = {GetBaseTypeValue(type)};"); } else { code.Append($@" //{field.Caption}"); for (int idx = 0; idx < len; idx++) { code.Append($@" {entityName}.{field.Name}[{idx}] = {GetBaseTypeValue(type)};"); } } }, (pro, en, len) => { code.Append($@" //{field.Caption} {CreateCsEntityCode(en, $"{entityName}.{field.Name}", false)};"); }, (pro, type, len) => { }, (pro, enumcfg, len) => { var value = enumcfg.Items[random.Next(enumcfg.Items.Count - 1)].Name; code.Append($@" //{field.Caption} {entityName}.{field.Name} ={enumcfg.Name}.{value};"); }); }
private static string FriendInc(EntityConfig entity) { var code = new StringBuilder(); foreach (var pro in entity.CppProperty) { var friend = CppTypeHelper.ToCppLastType(pro.CppLastType ?? pro.CppType) as EntityConfig; if (friend != null) code.Append($@" #include <{friend.Parent.Name}/{friend.Name}.h> #include <{friend.Parent.Name}/{friend.Name}_clr.h>"); } return code.ToString(); }
private static void ToJsonCode(StringBuilder code, PropertyConfig field, bool isFirst) { var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { FriendJson(code, field, isFirst); return; } var typedef = type as TypedefItem; if (typedef == null) { if (type.ToString() == "char") { StringJson(code, field, field.Datalen.ToString(), isFirst); } else if (field.Datalen > 0) { ArrayJson(code, field, field.Datalen.ToString(), isFirst); } else { NumberJson(code, field, isFirst); } return; } if (typedef.KeyWork == "char") { StringJson(code, field, typedef.ArrayLen, isFirst); } else if (field.Datalen > 0) { ArrayJson(code, field, field.Datalen.ToString(), isFirst); } else if (string.IsNullOrWhiteSpace(typedef.ArrayLen)) { NumberJson(code, field, isFirst); } else { ArrayJson(code, field, typedef.ArrayLen, isFirst); } }
private static void SetValue(StringBuilder code, PropertyConfig field) { var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { code.Append($@" memcpy(m_data.{field.Name},value,sizeof({stru.Name}));"); return; } var typedef = type as TypedefItem; var keyword = typedef == null?type.ToString() : typedef.KeyWork; var isArray = typedef == null ? field.Datalen > 0 : typedef.ArrayLen != null; if (keyword == "char" && isArray) { if (field.Datalen == 1 || typedef?.ArrayLen == "1") { code.Append($@" m_data.{field.Name} = value;"); } else { code.Append($@" strcpy_s(m_data.{field.Name},value);"); } } else if (isArray) { code.Append($@" memcpy(m_data.{field.Name},value,sizeof({field.Name}));"); } else { code.Append($@" m_data.{field.Name} = value;"); } }
private static string FriendInc(EntityConfig entity) { var code = new StringBuilder(); foreach (var pro in entity.CppProperty) { var friend = CppTypeHelper.ToCppLastType(pro.CppLastType ?? pro.CppType) as EntityConfig; if (friend != null) { code.Append($@" #include <{friend.Parent.Name}/{friend.Name}.h>"); } } if (!entity.IsReference) { return(code.ToString()); } var lc_entity = GlobalConfig.GetEntity(p => !p.IsReference && p.Option.ReferenceTag != null && p.Option.ReferenceTag.Contains(entity.Option.ReferenceTag)); if (lc_entity == null) { return(code.ToString()); } code.Append($@" #include <{lc_entity.Parent.Name}/{lc_entity.Name}.h>"); if (!string.IsNullOrWhiteSpace(entity.Parent.NameSpace)) { code.Append($@" using namespace {entity.Parent.NameSpace.Replace(".", "::")};"); } if (!string.IsNullOrWhiteSpace(lc_entity.Parent.NameSpace)) { code.Append($@" using namespace {lc_entity.Parent.NameSpace.Replace(".", "::")};"); } return(code.ToString()); }
public List <EntityConfig> CheckCppFieldes(string text) { List <EntityConfig> tables = new List <EntityConfig>(); string[] lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); int idx = 0; EntityConfig entity = new EntityConfig(); bool isNewTable = true; bool isInStruct = false; foreach (string l in lines) { if (string.IsNullOrEmpty(l)) { continue; } var line = l.Trim(' ', '\t', ';'); if (string.IsNullOrEmpty(line)) { continue; } switch (line) { case "{": isInStruct = true; continue; case "}": isNewTable = true; isInStruct = false; entity = new EntityConfig(); continue; } if (line.IndexOf("//", StringComparison.Ordinal) == 0) //注释 { if (isNewTable || line.Contains("//!")) { entity.Caption = line.Trim(CoderBase.NoneLanguageChar); isNewTable = false; } else { entity.Description = line.Trim(CoderBase.NoneLanguageChar); } continue; } string[] words = line.Split(new[] { ' ', ';', '\t' }, StringSplitOptions.RemoveEmptyEntries); switch (words[0]) { case "typedef": var item = new TypedefItem { Tag = SystemName }; var i = l.IndexOf('['); if (i < 0) { item.Name = words[words.Length - 1]; } else { var ks = l.Split(new[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries); item.ArrayLen = ks[1]; words = ks[0].Split(new[] { '\t', ' ', ';', '=' }, StringSplitOptions.RemoveEmptyEntries); } item.Description = entity.Caption; item.Name = words[words.Length - 1].Trim(CoderBase.NoneLanguageChar); item.KeyWork = string.Empty; for (int index = 1; index < words.Length - 1; index++) { item.KeyWork += " " + words[index]; } InvokeInUiThread(() => TypedefItems.Add(item)); continue; case "struct": entity.Name = words[1]; if (words.Length > 2) { entity.Caption = words[2].Trim(CoderBase.NoneNameChar); } tables.Add(entity); isInStruct = false; idx = 0; continue; case "private": case "protected": case "public": continue; } if (!isInStruct) { continue; } PropertyConfig column; entity.Properties.Add(column = new PropertyConfig { Index = idx++, DbType = "nvarchar" }); words = line.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length > 1) { column.Description = column.Caption = words[1].Trim('/', '\t', ' '); } words = words[0].Split(new[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length > 1) { column.Datalen = int.Parse(words[1].Trim('/', '\t', ' ')); } words = words[0].Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries); int nameIdx = words.Length - 1; column.Name = column.ColumnName = words[nameIdx].Trim(CoderBase.NoneLanguageChar); column.CppType = ""; for (int index = 0; index < nameIdx; index++) { if (index > 0) { column.CppType += " " + words[index]; } else { column.CppType = words[index]; } } } foreach (var t in tables) { t.Parent = Project; t.Tag = SystemName + "," + t.Name; t.CppName = t.Name; CoderBase.RepairConfigName(t, true); foreach (var pro in t.Properties) { pro.Parent = t; pro.CppName = pro.CppName; CoderBase.RepairConfigName(pro, true); pro.CppLastType = CppTypeHelper.CppLastType(pro.CppType); pro.CsType = CppTypeHelper.CppTypeToCsType(pro); } t.IsClass = true; //EntityBusinessModel business = new EntityBusinessModel //{ // Entity = t //}; //t.IsReference = true; //business.RepairByModel(true); //t.IsReference = false; } return(tables); }
private static void ToCppCopyCode(StringBuilder code, PropertyConfig field) { var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { code.Append($@" item->{field.Name} = CreateCsEntity(&field->{field.Name});//{field.Caption}"); return; } var typedef = type as TypedefItem; if (typedef == null) { if (type.ToString() == "char") { if (field.Datalen > 0) { code.Append($@" item->{field.Name} = marshal_as<String^>(&field->{field.Name});//{field.Caption}"); } else { code.Append($@" buf[0] = field->{field.Name};//{field.Caption} item->{field.Name} = marshal_as<String^>(buf);"); } } else if (field.Datalen > 0) { if (field.Datalen > 0) { code.Append($@" item->{field.Name} = gcnew {type}();//{field.Caption} for each(auto vl in field->{field.Name}) item->{field.Name}->Add(vl);"); } } else { code.Append($@" item->{field.Name} = field->{field.Name};//{field.Caption}"); } return; } if (typedef.KeyWork == "char") { if (field.Datalen > 0 || typedef.ArrayLen != null) { code.Append($@" item->{field.Name} = marshal_as<String^>(&field->{field.Name});//{field.Caption}"); } else { code.Append($@" buf[0] = field->{field.Name};//{field.Caption} item->{field.Name} = marshal_as<String^>(buf);"); } } else if (field.Datalen > 0) { if (field.Datalen > 0) { code.Append($@" item->{field.Name} = gcnew {field.CsType}();//{field.Caption} for each(auto vl in field->{field.Name}) item->{field.Name}->Add(vl);"); } } else if (string.IsNullOrWhiteSpace(typedef.ArrayLen)) { code.Append($@" item->{field.Name} = field->{field.Name};//{field.Caption}"); } else { if (field.Datalen > 0) { code.Append($@" item->{field.Name} = gcnew {type}();//{field.Caption} for each(auto vl in field->{field.Name}) quote->{field.Name}->Add(field.{field.Name}[i]);"); } } }
private static void ToCppReadCode(StringBuilder code, PropertyConfig field) { var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { if (field.Datalen == 1) { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} {{ int len = reader.ReadInt32(); char* buffer = reader.ReadBinrary2(len); Deserializer deserializer(buffer,len,true); Deserialize(deserializer,&field->{field.Name}[0]); }} break;"); } else if (field.Datalen > 0) { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} {{ int cnt = reader.ReadInt32(); for(int idx = 0;i < cnt;i++) {{ char* buffer = reader.ReadBinrary(len); Deserializer deserializer(buffer,len,true); Deserialize(deserializer,&field->{field.Name}[idx]); }} }} break;"); } else { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} {{ int len = reader.ReadInt32(); char* buffer = reader.ReadBinrary2(len); Deserializer deserializer(buffer,len,true); Deserialize(deserializer,&field->{field.Name}); }} break;"); } return; } var typedef = type as TypedefItem; var keyword = typedef == null?type.ToString() : typedef.KeyWork; var isArray = typedef == null ? field.Datalen > 0 : typedef.ArrayLen != null; if (keyword == "char" && isArray) { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} reader.ReadString(field->{field.Name}); break;"); } else if (isArray) { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} reader.ReadArray<{keyword}>(&field->{field.Name}); break;"); } else { code.Append($@" case IDX_{field.Parent.ReadTableName}_{field.Name}://{field.Caption} reader.Read<{keyword}>(&field->{field.Name}); break;"); } }
public static void GetRandomValue(StringBuilder code, PropertyConfig field, string entityName) { CppTypeHelper.DoByCppType(field.Parent, field, (pro, len) => { int len2 = (len - 1) / 2; var value = TestLine[random.Next(TestLine.Length - 1)]; if (value.Length > len2) { value = value.Substring(0, len2); } code.Append($@" //{field.Caption} -- char[{len}] strcpy_s({entityName}.{field.Name},""{value}"");"); }, (pro, type, len) => { if (type == "tm") { DateTime tm = DateTime.Now; code.Append($@" //{field.Caption} -- {type} {entityName}.{field.Name}.tm_year = {tm.Year }; {entityName}.{field.Name}.tm_mon = {tm.Month }; {entityName}.{field.Name}.tm_mday = {tm.Day }; {entityName}.{field.Name}.tm_hour = {tm.Hour}; {entityName}.{field.Name}.tm_min = {tm.Minute}; {entityName}.{field.Name}.tm_sec = {tm.Second};"); } else if (len <= 0) { code.Append($@" //{field.Caption} -- {type} {entityName}.{field.Name} = {GetBaseTypeValue(type)};"); } else { code.Append($@" //{field.Caption} -- {type}[{len}]"); for (int idx = 0; idx < len; idx++) { code.Append($@" {entityName}.{field.Name}[{idx}] = {GetBaseTypeValue(type)};"); } } }, (pro, en, len) => { code.Append($@" //{field.Caption} -- {en.Caption} {CreateEntityCode(en, $"{entityName}.{field.Name}", false)};"); }, (pro, type, len) => { var value = type.Items.Values.ToArray()[random.Next(type.Items.Count - 1)].Value; if (value == "'") { value = "'\\0'"; } code.Append($@" //{field.Caption} -- {type} {entityName}.{field.Name} = {value};"); }, (pro, enumcfg, len) => { var value = enumcfg.Items[random.Next(enumcfg.Items.Count - 1)].Name; code.Append($@" //{field.Caption} -- {enumcfg} {entityName}.{field.Name} = GBS::Futures::{enumcfg.Name}Classify::{value};"); }); }
private static void ToLogCode(StringBuilder code, PropertyConfig field) { if (field.IsIntDecimal) { IntDecimalLog(code, field); return; } if (field.EnumConfig != null) { InlineLog(code, field); return; } var type = CppTypeHelper.ToCppLastType(field.CppLastType ?? field.CppType); if (type == null) { return; } var stru = type as EntityConfig; if (stru != null) { FriendLog(code, field); return; } var typedef = type as TypedefItem; if (typedef == null) { string tp = type.ToString(); if (tp == "char") { if (field.Datalen > 1) { StringLog(code, field, field.Datalen.ToString()); } else { CharLog(code, field); } } else if (!string.IsNullOrWhiteSpace(field.ArrayLen)) { ArrayLog(code, field, field.ArrayLen); } else if (tp == "tm") { InlineLog(code, field); } else { NumberLog(code, field); } return; } if (typedef.Items.Count > 0) { TypeDefLog(code, field, typedef); } else if (typedef.KeyWork == "char") { if (field.Datalen > 1) { StringLog(code, field, typedef.ArrayLen); } else { CharLog(code, field); } } else if (string.IsNullOrWhiteSpace(typedef.ArrayLen)) { NumberLog(code, field); } else { ArrayLog(code, field, typedef.ArrayLen); } }
public static void FieldCmp(StringBuilder code, PropertyConfig field) { CppTypeHelper.DoByCppType(field.Parent, field, (pro, len) => { code.Append($@" if(strcmp(field_org.{field.Name},field_dec.{field.Name}) != 0) {{ succeed = false; cout << "" {field.Caption}失败:"" << field_org.{field.Name} << ""***""<<field_dec.{field.Name}<<endl; }}"); }, (pro, type, len) => { if (type == "tm" || len > 1) { code.Append($@" if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0) {{ succeed = false; cout << "" {field.Caption}失败:"" <<endl; }}"); } else { code.Append($@" if( field_org.{field.Name} != field_dec.{field.Name}) {{ succeed = false; cout << "" {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl; }}"); } }, (pro, en, len) => { code.Append($@" if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof({en.Name})) != 0) {{ succeed = false; cout << "" {field.Caption}失败:"" <<endl; }}"); }, (pro, ty, len) => { if (len > 1) { code.Append($@" if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0) {{ succeed = false; cout << "" {field.Caption}失败:"" <<endl; }}"); } else { code.Append($@" if( field_org.{field.Name} != field_dec.{field.Name}) {{ succeed = false; cout << "" {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl; }}"); } }, (pro, em, len) => { if (len > 1) { code.Append($@" if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0) {{ succeed = false; cout << "" {field.Caption}失败:"" <<endl; }}"); } else { code.Append($@" if( field_org.{field.Name} != field_dec.{field.Name}) {{ succeed = false; cout << "" {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl; }}"); } }); }
public static string FriendFieldCopy(PropertyConfig srcField, PropertyConfig destField, string src_field_name, string dest_field_name, string cpName) { var type = CppTypeHelper.ToCppLastType(srcField.CppLastType ?? srcField.CppType); var stru = type as EntityConfig; if (stru != null) { if (srcField.CppLastType == destField.CppLastType) { return ($@" memcpy(&{dest_field_name},&{src_field_name},sizeof({destField.CppLastType}));//{ srcField.Caption}"); } return($@" {cpName}(&{src_field_name},&{dest_field_name});//{srcField.Caption}"); } if (srcField.CppLastType == "char") { if (srcField.Datalen > 1) { return($@" strcpy_s({dest_field_name},{src_field_name});//{srcField.Caption}" ); } return($@" {dest_field_name} = {src_field_name};//{srcField.Caption}"); } if (!CppTypeHelper.IsCppBaseType(srcField.CppLastType)) { if (!string.IsNullOrEmpty(srcField.ArrayLen)) { return ($@" if({src_field_name} != nullptr)//{srcField.Caption } {{ for(int idx = 0;idx < {srcField.ArrayLen};idx++) memcpy({ dest_field_name}[idx],{src_field_name}[idx], sizeof({srcField.CppLastType})); }}"); } return ($@" memcpy({dest_field_name},{src_field_name}, sizeof({srcField.CppLastType}));//{ srcField.Caption}"); } if (!string.IsNullOrEmpty(srcField.ArrayLen)) { return ($@" if({src_field_name} != nullptr)//{srcField.Caption } {{ for(int idx = 0;idx < {srcField.ArrayLen};idx++) { dest_field_name}[idx] = {src_field_name}[idx]; }}"); } return($@" {dest_field_name} = {src_field_name};//{srcField.Caption}"); }
private EntityConfig GetLcEntity(PropertyConfig field) { return(CppTypeHelper.ToCppLastType(field.CppLastType ?? field.CppType) as EntityConfig); }
private static void ToCppWriteCode(StringBuilder code, PropertyConfig field) { var type = CppTypeHelper.ToCppLastType(field.CppLastType); var stru = type as EntityConfig; if (stru != null) { if (field.Datalen == 1) { code.Append($@" {{ Serializer serializer; Serialize(serializer,&field->{field.Name}[0]); wtiter.WriteObject(serializer); }}"); } else if (field.Datalen > 0) { code.Append($@" case IDX_{field.Parent.Name.ToUpper()}_{field.Name.ToUpper()}://{field.Caption} {{ wtiter.WriteType(OBJ_TYPE_OBJECT_ARRAY); wtiter.Write({field.Datalen}); for(int idx = 0;i < {field.Datalen};i++) {{ Serializer serializer; Serialize(serializer,&field->{field.Name}[idx]); wtiter.Write(serializer); }} }} break;"); } else { code.Append($@" {{ Serializer serializer; Serialize(serializer,&field->{field.Name}); wtiter.WriteObject(serializer); }}"); } return; } var typedef = type as TypedefItem; var keyword = typedef == null?type.ToString() : typedef.KeyWork; var isArray = typedef == null ? field.Datalen > 0 : typedef.ArrayLen != null; if (keyword == "char" && isArray) { if (field.Datalen == 1 || typedef?.ArrayLen == "1") { code.Append($@" wtiter.Write(field->{field.Name}[0]);"); } else { code.Append($@" wtiter.Write(field->{field.Name});"); } } else if (isArray) { code.Append($@" wtiter.Write(field->{field.Name},{(typedef == null ? field.Datalen.ToString() : typedef.ArrayLen)});"); } else { code.Append($@" wtiter.Write(field->{field.Name});"); } }