1 /* Copyright (C) 2012  Olga Yakovleva <yakovleva.o.v@gmail.com> */
2 
3 /* This program is free software: you can redistribute it and/or modify */
4 /* it under the terms of the GNU Lesser General Public License as published by */
5 /* the Free Software Foundation, either version 2.1 of the License, or */
6 /* (at your option) any later version. */
7 
8 /* This program is distributed in the hope that it will be useful, */
9 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
10 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
11 /* GNU Lesser General Public License for more details. */
12 
13 /* You should have received a copy of the GNU Lesser General Public License */
14 /* along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15 
16 #ifndef RHVOICE_SAPI_ISPDATAKEYIMPL_HPP
17 #define RHVOICE_SAPI_ISPDATAKEYIMPL_HPP
18 
19 #include <string>
20 #include <map>
21 #include <functional>
22 #include <windows.h>
23 #include <sapi.h>
24 #include <sapiddk.h>
25 #include <sperror.h>
26 
27 #include "core/utf.hpp"
28 #include "core/str.hpp"
29 #include "com.hpp"
30 
31 namespace RHVoice
32 {
33   namespace sapi
34   {
35     class ISpDataKeyImpl: public ISpDataKey
36     {
37     public:
38       STDMETHOD(SetData)(LPCWSTR pszValueName,ULONG cbData,const BYTE *pData);
39       STDMETHOD(GetData)(LPCWSTR pszValueName,ULONG *pcbData,BYTE *pData);
40       STDMETHOD(SetStringValue)(LPCWSTR pszValueName,LPCWSTR pszValue);
41       STDMETHOD(GetStringValue)(LPCWSTR pszValueName,LPWSTR *ppszValue);
42       STDMETHOD(SetDWORD)(LPCWSTR pszValueName,DWORD dwValue);
43       STDMETHOD(GetDWORD)(LPCWSTR pszKeyName,DWORD *pdwValue);
44       STDMETHOD(OpenKey)(LPCWSTR pszSubKeyName,ISpDataKey **ppSubKey);
45       STDMETHOD(CreateKey)(LPCWSTR pszSubKeyName,ISpDataKey **ppSubKey);
46       STDMETHOD(DeleteKey)(LPCWSTR pszSubKeyName);
47       STDMETHOD(DeleteValue)(LPCWSTR pszValueName);
48       STDMETHOD(EnumKeys)(ULONG Index,LPWSTR *ppszSubKeyName);
49       STDMETHOD(EnumValues)(ULONG Index,LPWSTR *ppszValueName);
50 
51     protected:
52       struct str_less: public std::binary_function<const std::wstring&,const std::wstring&,bool>
53       {
operator ()RHVoice::sapi::ISpDataKeyImpl::str_less54         bool operator()(const std::wstring& s1,const std::wstring& s2) const
55         {
56           std::wstring::const_iterator pos1=s1.begin();
57           std::wstring::const_iterator pos2=s2.begin();
58           utf8::uint32_t cp1,cp2;
59           while((pos1!=s1.end())&&(pos2!=s2.end()))
60             {
61               cp1=str::tolower(utf::next(pos1,s1.end()));
62               cp2=str::tolower(utf::next(pos2,s2.end()));
63               if(cp1!=cp2)
64                 return (cp1<cp2);
65             }
66           return ((pos1==s1.end())&&(pos2!=s2.end()));
67         }
68       };
69 
70     private:
71       typedef std::map<std::wstring,std::wstring,str_less> value_map;
72 
73       std::wstring default_value;
74       value_map values;
75 
76     public:
set(const std::wstring & name,const std::wstring & value)77       void set(const std::wstring& name,const std::wstring& value)
78       {
79         values[name]=value;
80       }
81 
set(const std::wstring & value)82       void set(const std::wstring& value)
83       {
84         default_value=value;
85       }
86 
87     protected:
get_interface(REFIID riid)88       void* get_interface(REFIID riid)
89       {
90         return com::try_primary_interface<ISpDataKey>(this,riid);
91       }
92     };
93   }
94 }
95 #endif
96