sbPropertyUnitConverter.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef __SBPROPERTYUNITCONVERTER_H__
28 #define __SBPROPERTYUNITCONVERTER_H__
29 
30 #include "sbIPropertyUnitConverter.h"
31 #include "sbIPropertyManager.h"
32 #include <nsIStringBundle.h>
33 #include <nsStringGlue.h>
34 #include <nsIWeakReference.h>
35 #include <nsIWeakReferenceUtils.h>
36 #include <nsCOMArray.h>
37 #include <nsCOMPtr.h>
38 #include <map>
39 #include <list>
40 
41 // sbPropertyUnit class - describes a unit exposed by sbIPropertyUnitConverter
43 public:
45  NS_DECL_SBIPROPERTYUNIT
46 
48  sbPropertyUnit(const nsAString& aName,
49  const nsAString& aShortName,
50  const nsAString& aID);
51  virtual ~sbPropertyUnit();
52 
53  NS_IMETHODIMP Init(const nsAString & aName,
54  const nsAString & aShortName,
55  const nsAString &aID);
56 
57 protected:
58 
59  PRLock *mLock;
60  nsString mName;
61  nsString mShortName;
62  nsString mID;
63  PRBool mInitialized;
64 };
65 
66 // sbPropertyUnitConverter class - exposes the units and the conversion function
68 public:
70  NS_DECL_SBIPROPERTYUNITCONVERTER
71 
73  virtual ~sbPropertyUnitConverter();
74 
75 protected:
76  void RegisterUnit(PRUint32 aUnitInternalID,
77  const nsAString &aUnitExternalID,
78  const nsAString &aUnitName,
79  const nsAString &aUnitShortName,
80  PRBool isNative = PR_FALSE);
81 
82  void SetStringBundle(const nsAString &aStringBundle);
83 
84 
85  NS_IMETHOD ConvertFromNativeToUnit(PRFloat64 aValue,
86  PRUint32 aUnitID,
87  PRFloat64 &_retVal)=0;
88  NS_IMETHOD ConvertFromUnitToNative(PRFloat64 aValue,
89  PRUint32 aUnitID,
90  PRFloat64 &_retVal)=0;
91 
92  virtual PRInt32 GetAutoUnit(PRFloat64 aValue) { return -1; }
93  nsresult PerformConversion(PRFloat64 &aValue,
94  PRUint32 aFromUnit,
95  PRUint32 aToUnit);
96 
97  void RemoveTrailingZeroes(nsAString &aValue);
98  void LimitToNDecimals(nsAString &aValue, PRUint32 aDecimals);
99  void ForceToNDecimals(nsAString &aValue, PRUint32 aDecimals);
100  void ApplyDecimalLimits(nsAString &aValue,
101  PRInt32 aMinDecimals,
102  PRInt32 aMaxDecimals);
103 
104  PRLock* mLock;
105  nsString mNative;
106  PRUint32 mNativeInternal;
107  nsString mStringBundle;
108  nsCOMPtr<nsIStringBundleService> mStringBundleService;
109  nsCOMPtr<nsIStringBundle> mStringBundleObject;
110 
111  typedef struct {
112  nsCOMPtr<sbIPropertyUnit> mUnit;
113  PRUint32 mInternalId;
114  } propertyUnit;
115 
116  class propertyUnitMap : public std::map<nsString, propertyUnit> {};
117  class propertyUnitMapInternal : public std::map<PRUint32, propertyUnit> {};
118  class propertyUnitList : public std::list<propertyUnit> {};
122 
123  PRUnichar mDecimalPoint;
124 
125  nsCOMPtr<nsIWeakReference> mPropertyInfo;
126  nsresult SscanfFloat64(const nsAString &aValue, PRFloat64 &aOutValue);
127  nsresult SprintfFloat64(const PRFloat64 aValue, nsAString &aOutValue);
128 };
129 
130 #endif // __SBPROPERTYUNITCONVERTER_H__
NS_DECL_ISUPPORTS NS_DECL_SBIPROPERTYUNIT sbPropertyUnit()
propertyUnitMapInternal mUnitsMapInternal
void ApplyDecimalLimits(nsAString &aValue, PRInt32 aMinDecimals, PRInt32 aMaxDecimals)
nsresult SprintfFloat64(const PRFloat64 aValue, nsAString &aOutValue)
onPageChanged aValue
Definition: FeedWriter.js:1395
Property unit interface This interface describes a property unit.
nsresult SscanfFloat64(const nsAString &aValue, PRFloat64 &aOutValue)
NS_IMETHODIMP Init(const nsAString &aName, const nsAString &aShortName, const nsAString &aID)
void ForceToNDecimals(nsAString &aValue, PRUint32 aDecimals)
nsCOMPtr< nsIWeakReference > mPropertyInfo
void RemoveTrailingZeroes(nsAString &aValue)
NS_IMETHOD ConvertFromUnitToNative(PRFloat64 aValue, PRUint32 aUnitID, PRFloat64 &_retVal)=0
void LimitToNDecimals(nsAString &aValue, PRUint32 aDecimals)
nsCOMPtr< nsIStringBundle > mStringBundleObject
virtual PRInt32 GetAutoUnit(PRFloat64 aValue)
_updateCookies aName
Property unit converter interface This is an interface songbird property converter, used to convert a property value between its various units representations.
void RegisterUnit(PRUint32 aUnitInternalID, const nsAString &aUnitExternalID, const nsAString &aUnitName, const nsAString &aUnitShortName, PRBool isNative=PR_FALSE)
nsresult PerformConversion(PRFloat64 &aValue, PRUint32 aFromUnit, PRUint32 aToUnit)
NS_IMETHOD ConvertFromNativeToUnit(PRFloat64 aValue, PRUint32 aUnitID, PRFloat64 &_retVal)=0
NS_DECL_ISUPPORTS NS_DECL_SBIPROPERTYUNITCONVERTER sbPropertyUnitConverter()
void SetStringBundle(const nsAString &aStringBundle)
nsCOMPtr< nsIStringBundleService > mStringBundleService