对于想了解如何使用反射将map[interface{}]interface{}转换为map[string]string的读者,本文将提供新的信息,我们将详细介绍反射获取map的属性,并且为您提供关于A
对于想了解如何使用反射将 map[interface{}]interface{} 转换为 map[string]string的读者,本文将提供新的信息,我们将详细介绍反射获取map的属性,并且为您提供关于Approximating Translucency for a Fast, Cheap and Convincing Subsurface-Scattering Look、DECLARE_META_INTERFACE(INTERFACE)和IMPLEMENT_META_INTERFACE(INTERFACE, NAME)宏定义分析、freemarker 如何遍历 Map
- 如何使用反射将 map[interface{}]interface{} 转换为 map[string]string(反射获取map的属性)
- Approximating Translucency for a Fast, Cheap and Convincing Subsurface-Scattering Look
- DECLARE_META_INTERFACE(INTERFACE)和IMPLEMENT_META_INTERFACE(INTERFACE, NAME)宏定义分析
- freemarker 如何遍历 Map
> ? - gob:类型未注册的接口:map [string] interface {}
如何使用反射将 map[interface{}]interface{} 转换为 map[string]string(反射获取map的属性)
如何解决如何使用反射将 map[interface{}]interface{} 转换为 map[string]string?
我有一个结构
type ClientSubscriptions struct {
ID int64
Service string
Identifier string
EventType string
DateBegin *time.Time
DateEnd *time.Time
Extra map[string]string
}
而且我有一个原始来源,它向我发送了一些数据。我在解析 int64、string 和 time 等类型时没有问题。但我无法将 json 对象 Extra 转换为我的结构
func parseSubscription(data []interface{}) (*ClientSubscriptions,error) {
if len(data) == 0 {
return nil,nil
}
res := ClientSubscriptions{}
values := reflect.ValueOf(&res).Elem()
controlTupleSize := values.NumField()
if len(data) < controlTupleSize {
return nil,fmt.Errorf("unexpected control tuple size %d,want %d",len(data),controlTupleSize)
}
for i,v := range data {
value := values.Field(i)
switch value.Interface().(type) {
case int64:
val,err := utils.ParsetoInt64(v)
if err != nil {
return nil,err
}
value.SetInt(val)
case *time.Time:
val := v.(uint64)
date := time.Unix(int64(val),0)
value.Set(reflect.ValueOf(&date))
case string:
val := v.(string)
value.SetString(val)
case interface{}:
val := v.(map[string]interface{})
if len(val) > 0 {
for key,info := range val {
strKey := fmt.Sprintf("%v",key)
strValue := fmt.Sprintf("%v",info)
value.SetMapIndex(reflect.ValueOf(strKey),reflect.ValueOf(strValue))
}
}
}
}
return &res,nil
}
panic:分配到 nil map 中的条目
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Approximating Translucency for a Fast, Cheap and Convincing Subsurface-Scattering Look
link:
http://www.slideshare.net/colinbb/colin-barrebrisebois-gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurfacescattering-look-7170855
Dice 的
效果图:
SubSurfaceScattering 和 IndirectLighting 技术逐渐开始成熟了。
这篇文章主要就是说这种半透不透的,带散射的情况。
透射属于比较 “意境” 化得 feature,不像 direct lighting 那么的需要准确,所以 “意思意思” 就可以给玩家很棒的感觉,从这个 “意思意思” 走到完全准确能提升的观感非常有限。
描述散射需要用:BSDF(bidirectional scatering distribution function)类似 BRDF 是描述散射的
当然这个太费了,需要用 hack 的办法。
crysis1 用的是美术直接生成透明度贴图的方式来模拟的,效果很不错:
Dice 也是类似的思路,是 offline 的一个 texture 来代表这一部分的透明程度。
这个算法是针对类似翡翠这一类的东西,不是玻璃这一类的特透明的。
所以透明度只要关心厚度就可以了,这个厚度也不用那么较真,就是把 normal 反一下,然后从内部算 AO 就可以,这个过程 offline 的,需要准确,所以就不能使 ssao 这种的了,需要 geometry space 的。
有了厚度贴图之后其他的就顺理成章了:
透明度由于不需要 alpha blending 可以存在 g buffer 里面,可以存一个灰度或者带颜色的。
dice 的 g buffer 里面有 material id 和 env id,这个有点意思。
原文链接: http://blog.csdn.net/ccanan/article/details/6277163
DECLARE_META_INTERFACE(INTERFACE)和IMPLEMENT_META_INTERFACE(INTERFACE, NAME)宏定义分析
定义
frameworks\base\include\utils\IInterface.h
|
说明:其中的I##INTERFACE,##表示连接两个宏定义,在这里INTERFACE是模板名,被当作是宏定义。如果INTERFACE是ServiceManager那么I##INTERFACE就是IServiceManager。
使用:例子ICameraService
定义声明的宏定义:DECLARE_META_INTERFACE(INTERFACE)
ICameraService.h [frameworks\base\include\ui]
|
把这句展开就是:
|
就是说在ICameraService接口类中定义了一个String16的变量和两个函数。
然后在ICameraService.cpp [frameworks\base\libs\ui]中定义另外一个实现的宏定义。
就这么一句:
|
展开为:
|
展开就是说初始化了一个变量descriptor,实现了BpCameraService类的2个函数:getInterfaceDescriptor (), asInterface()。而且这个宏定义不属于在这个cpp文件中定义的BpCameraService类和在.h文件中定义的BnCameraService类。
在Camera.cpp [frameworks\base\libs\ui]中
const sp& Camera::getCameraService()函数调用
mCameraService = interface_cast(binder);
著名的interface_cast函数
|
interface_cast调用的是宏定义中的asInterface函数,然后返回的是new BpCameraService (obj)对象。
freemarker 如何遍历 Map> ?
这样竟然不好用。。。
<#list stationStationFailureMap?keys as key>
<#list stationStationFailureMap[key]?keys as k>${(stationStationFailureMap[key])[k]}
</#list>
</#list>
直接这样可以出来东西,但是想得到 stationStationFailureMapOfAll.get ("key") 就不好用了
<#assign stationStationFailureMapOfAll = stationStationFailureMap["all"]>
<#list stationStationFailureMapOfAll?keys as stationStation>
<td>${stationStation}</td>
<#--<#assign values = stationStationFailureMapOfAll ["武昌 - 苏州"]>
<td>${values}</td>-->
</#list>
貌似 freemarker 把 stationStationFailureMapOfAll 当成了一个普通对象而不是 map 来处理。
如何解决?
本来是用 velocity 的,没有这个问题。但 velocity 保留两位小数,百分比啥的太难用了。
换成 freemarker 没想到出了这种问题。
gob:类型未注册的接口:map [string] interface {}
gob
无法编码 map[string]interface{}
gob: type not registered for interface: map[string]interface {}
http://play.golang.org/p/Si4hd8I0JE
package main
import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"log"
)
func CloneObject(a,b interface{}) []byte {
buff := new(bytes.Buffer)
enc := gob.NewEncoder(buff)
dec := gob.NewDecoder(buff)
err := enc.Encode(a)
if err != nil {
log.Panic("e1: ",err)
}
b1 := buff.Bytes()
err = dec.Decode(b)
if err != nil {
log.Panic("e2: ",err)
}
return b1
}
func main() {
var a interface{}
a = map[string]interface{}{"X": 1}
b2,err := json.Marshal(&a)
fmt.Println(string(b2),err)
var b interface{}
b1 := CloneObject(&a,&b)
fmt.Println(string(b1))
}
可以map[string]interface{}
在gob中编码吗?我可以用JSON编码
关于如何使用反射将 map[interface{}]interface{} 转换为 map[string]string和反射获取map的属性的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Approximating Translucency for a Fast, Cheap and Convincing Subsurface-Scattering Look、DECLARE_META_INTERFACE(INTERFACE)和IMPLEMENT_META_INTERFACE(INTERFACE, NAME)宏定义分析、freemarker 如何遍历 Map
本文标签: